Open PDF file on the fly from a Java application

I’d try Desktop.open(File), which:

Launches the associated application to open the file.

So this code should do the trick:

if (Desktop.isDesktopSupported()) {
    try {
        File myFile = new File("/path/to/file.pdf");
        Desktop.getDesktop().open(myFile);
    } catch (IOException ex) {
        // no application registered for PDFs
    }
}

Leave a Comment