java - How to load a PDF from a .jar File? -


I have created a swing application and it includes a file, 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.

I have the code to load the PDF,

  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 (); }}   

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 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

Popular posts from this blog

mysql - BLOB/TEXT column 'value' used in key specification without a key length -

c# - Using Vici cool Storage with monodroid -

python - referencing a variable in another function? -