windows - java open file with default program -


i need download file java server using socket, , open default windows program. i've explored several solution, none fits need. aim temporarily open file external default program , delete file when external program exits. i've found these solution:

  1. desktop.getdesktop.open(myfile), seems can't handle returned value check external program exit
  2. processbuilder, handles external program exit, not open "default windows program", , need check every file extension run associated command. solution quite "close", can't know in advance types of file open
  3. apache commons exec, seems same 2, more reliable same problem

what do?

think solution found, report others same needs:

  1. instead of use file=new file(), have used file=file.createtempfile(basename,extension) [you can use apache common io manage file name] create temporarily file
  2. set file deleted on software exit (not on current frame exit) file.deleteonexit()
  3. try open file default programm try{desktop.getdesktop().open(file)}
  4. catch exception handle case no default programm exists, in case software open file directory highlighting file
    catch(ioexception e){runtime.getruntime().exec("explorer.exe/select," +file.getabsolutepath()); }

Comments

Popular posts from this blog

javascript - Thinglink image not visible until browser resize -

firebird - Error "invalid transaction handle (expecting explicit transaction start)" executing script from Delphi -

mongodb - How to keep track of users making Stripe Payments -