• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

open a pdf file located inside a jar file.

 
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

I packed my swing application into an executable jar file.

I had a button that will open a pdf file located in a resources folder located in the root directory of the jar file.

the code I have in the jar file was



when executing the jar file. I click the button that is supposed to launch the pdf file. i get the following exception

java.lang.IllegalArgumentException: the file file:\c:\Desktop.jar!\resources\User_Guide.pdf doesn't exist.

any help?

the spelling of the file name is correct

 
Sammy Bill
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I also tried to put the file in a server and just use:

File file = new File ( new URL("http://...............").getPath()).

but did not also work.

it says file does not exist.
 
Sheriff
Posts: 22849
132
Eclipse IDE Spring Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can't do this the easy way; all you can get is an InputStream to the resource.

So, create a temporary file, write the PDF resource to it, and open that:
 
reply
    Bookmark Topic Watch Topic
  • New Topic