I’m using Java SE 6 and want to open files in an external process by a predefined program. Currently I am using the following code for pdf files for example:
Windows:
public static Process openFile(File file) {
return Runtime.getRuntime().exec("C:/Program Files (x86)/Adobe/Reader 10.0/Reader/AcroRd32.exe \""+file.getAbsolutePath()+"\"");
}
Ubuntu Linux:
public static Process openFile(File file) {
return Runtime.getRuntime().exec("/usr/bin/evince \""+file.getAbsolutePath()+"\"");
}
On windows this works just fine for all files. But on ubuntu, as soon as there’s a space within the file path, it tries to open multiple files. Here’s an example:
contract.pdf -> works on windows and ubuntu
contract 1 (copy).pdf -> works only on windows, ubuntu tries to open 3 different files (contract, 1, and (copy).pdf)
What special character do I need to tell ubuntu that it should handle file paths with spaces as one file ?
Thanks for your help in advance!
Best regards
I would try using Desktop.open
Or you can try