aspose file tools*
The moose likes I/O and Streams and the fly likes Reading file from jar file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "Reading file from jar file" Watch "Reading file from jar file" New topic
Author

Reading file from jar file

Gail Mikels
Ranch Hand

Joined: May 07, 2001
Posts: 634
I am trying to read a file that I'm using as a template. The template file is in the deployed jar file for my application. I'm thinking my syntax for reading a file from a jar file is incorrect, though I've tried several examples I've found, and none seem to work.

Here's my code snippet:




And here's the relevent output & error:



I've searched online & it seems that I'm doing it right. But obviously I'm not! I've tried making the slashes go the other way, tried finding other files in that same directory (also unsuccessful), opened up my jar file to verify that my template file is at the path I'm looking at. To no avail.

Any ideas?? :-)


Gail Mikels
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

Resources inside jar files aren't "files". Only things on disks that your operating system manages as files are "files". So you can't use a FileInputStream. Do this instead:
Gail Mikels
Ranch Hand

Joined: May 07, 2001
Posts: 634
Oh. <duh>

Thank you very much!!! :-D
Arvind Subramanian
Ranch Hand

Joined: Jul 25, 2008
Posts: 84
thannks very much... the exact answer which i confused...


"Many of lifes failure are people who did not realize how close they were to success when they gave up."
-Thomas Edison
~ar~stutzen~
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Reading file from jar file