java - How to load a PDF from a .jar File? -
I have created a swing application and it includes a file, I have the code to load the PDF, This eclipse works in the IDE, however, when I pack it in a jar for other people it does not work anymore. How can I fix this problem? The problem is that a help.pdf in .jar File will be When the user selects a
help-> user guide from a JNNUTime, then it should load the file in the default PDF viewer on the system.
private zero openHelp () {try {java.net.URL helpFile = getClass (). GetClassLoader (). GetResource ("help.pdf"); File pdf file = new file (helpFile.getPath ()); If (pdfFile.exists ()) {if (Desktop.isDesktopSupported ()) {Desktop.getDesktop (). Open (pdfFile); } Else {System.out.println ("Awt desktop is not supported!"); }} And {System.out.println ("File does not exist!"); } System.out.println ("Done"); } Hold (Exception pre) {ex.printStackTrace (); }}
file is not the name of a component of a jar File can be given. What you need to do is to copy the resource from the file system to a temporary file in the file system, and open it using the
file for the temporary file.
Comments
Post a Comment