java - Need help to find the filename -


i used following code run exe load through code.

private static string filelocation = ""; 

.

  load_exe.addactionlistener(new actionlistener() {       @override      public void actionperformed(actionevent e) {         try {            jfilechooser file_choose = new jfilechooser();             file_choose.showopendialog(frame);            javasamp.filelocation = file_choose.getcurrentdirectory()                     .tostring()                     + "\\" + file_choose.getselectedfile().getname();            system.out.println("filelocation" + javasamp.filelocation);         } catch (exception expobj) {            // todo auto-generated catch block         }         runtime rt = runtime.getruntime();          try {            system.out.println("file run location" + javasamp.filelocation);            proc = rt.exec(javasamp.filelocation);          } catch (ioexception e4) {            e4.printstacktrace();         } catch (exception e2) {          }      }   }); 

my problem is, above execution of javasamp.filelocation, should have done many times. first time load exe. next time wont. need store exe in string run successive times. suggestion pls

if want remember used file initialize filelocation null , test it. btw: storing file makes more sense , way of constructing absolute path bit intricate - compared calling getabsolutepath()

private static file filelocation = null;  private static void test() {     load_exe.addactionlistener(new actionlistener() {          public void actionperformed(actionevent e) {             // check if file-name execute has been set             if (filelocation != null) {                 try {                     jfilechooser file_choose = new jfilechooser();                      file_choose.showopendialog(frame);                     javasamp.filelocation = file_choose.getselectedfile();                     system.out.println("filelocation"                             + javasamp.filelocation.getabsolutepath());                 } catch (exception expobj) {                 }             }             runtime rt = runtime.getruntime();              try {                 system.out.println("file run location"                         + javasamp.filelocation.getabsolutepath());                 process proc = rt.exec(javasamp.filelocation                         .getabsolutepath());              } catch (ioexception e4) {                 e4.printstacktrace();             }         }     }; } 

Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -