Try it,
try{ if ((new File("c:\\your_file.pdf")).exists()) { Process p = Runtime .getRuntime() .exec("rundll32 url.dll,FileProtocolHandler c:\\your_file.pdf"); p.waitFor(); } else { System.out.println("File does not exist"); } } catch (Exception ex) { ex.printStackTrace(); }
or you can do it using Desktop.open(File) ,
if (Desktop.isDesktopSupported()) { try { File myFile = new File("/path/to/file.pdf"); Desktop.getDesktop().open(myFile); } catch (IOException ex) { // no application registered for PDFs } }
You can also open pptx files (and more) with this approach.
sikander
source share