I have a program, that after the user puts in some information, they click a button to exectute the program. I want the code to check to see if a file exists before executing the program.
I need my program to look in the same directotry that it is running from for a .lic file. Then if it does not exeist to alert the user that there is no license installed and to follow the readme instrucitons found in the running directory.
Here is my coding for the button execution.
private void btnRunRelapActionPerformed(java.awt.event.ActionEvent evt) { String in = tfIntdta.getText(); String rst = tfRstplt.getText(); String out = tfOutdta.getText(); String strip = tfStpdta.getText(); String guistring = "-n gui"; String wd = System.getProperty("user.dir"); String osver = System.getProperty("os.name"); String exec = ""; if (osver.contains("Mac OS X")){ exec = "/Users/brian.allison/rs40/relap5.x"; } else if (osver.contains("linux")) { exec = "relap5.x"; } else if (osver.contains("windows")) { exec = "relap5.exe"; } try{ String Fileout = tfOutdta.getText(); //Delete if tempFile exists File fileout = new File(Fileout); if (fileout.exists()){ fileout.delete(); } }catch(Exception e){ // if any error occurs } // if (cbDelRstplt.isSelected()) { try{ String Filerst = tfOutdta.getText(); //Delete if File exists File filerst = new File(Filerst); if (filerst.exists()){ filerst.delete(); } }catch(Exception e){ // if any error occurs } } String[] cmd = {exec, "-i", in, "-r", rst, "-o", out}; if (tfStpdta.isVisible()) { String[] cmd2 = {exec, "-i", in, "-r", rst, "-o", out, "-s", strip}; cmd = cmd2; } else if (cb3DGui.isSelected()) { String[] cmd3 = {exec, "-i", in, "-r", rst, "-o", out, "-n", "gui"}; cmd = cmd3; } System.out.println(strip); if // try{ Runtime.getRuntime().exec(cmd); } catch (IOException ex) { }