Possible Duplicate:
How to launch the default (native) application for a given file from Java?
I have a java application that opens a file. This works perfect on windows, but not on mac.
The problem here is that I use the windows configuration to open it. The code is:
Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler " + file);
Now my question is what is the code to open it in mac? Or is there another way to open a PDF that works multi platform?
EDIT:
I created the file as followed:
File folder = new File("./files");
File[] listOfFiles = folder.listFiles();
in a loop i add them to an array:
fileArray.add(listOfFiles[i]);
If i try to open a file from that array with Desktop.getDesktop().open(file), it says it can’t find that file (the path is messed up because I used ‘./files’ as folder)
Here is an OperatingSystem Detector:
Then you can open files like this:
Answer to your edit:
Try to use
file.getAbsoluteFile()or evenfile.getCanonicalFile().