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:
desktop.getdesktop.open(myfile)
, seems can't handle returned value check external program exitprocessbuilder
, 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- apache commons exec, seems same 2, more reliable same problem
what do?
think solution found, report others same needs:
- instead of use
file=new file()
, have usedfile=file.createtempfile(basename,extension)
[you can use apache common io manage file name] create temporarily file - set file deleted on software exit (not on current frame exit)
file.deleteonexit()
- try open file default programm
try{desktop.getdesktop().open(file)}
- 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
Post a Comment