CoderSpace Ghrce

How to open .pdf file in java

Java Swing 💻

if (Desktop.isDesktopSupported()) { try { ClassLoader classLoader = getClass().getClassLoader(); File myFile = new File(classLoader.getResource(“package/file.pdf”).getFile()); Desktop.getDesktop().open(myFile); } catch (IOException ex) { //Control the exception } }

Thanks!