Search code examples
javaexternal-application

Open a file with an external application on Java


How do you open a file from a java application when you do not know which application the file is associated with. Also, because I'm using Java, I'd prefer a platform independent solution.


Solution

  • With JDK1.6, the java.awt.Desktop class can be useful.

    public static void open(File document) throws IOException {
        Desktop dt = Desktop.getDesktop();
        dt.open(document);
    }