aspose file tools*
The moose likes I/O and Streams and the fly likes Help!  Accessing files in a JAR file at Runtime Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "Help!  Accessing files in a JAR file at Runtime" Watch "Help!  Accessing files in a JAR file at Runtime" New topic
Author

Help! Accessing files in a JAR file at Runtime

Chris Merritt
Greenhorn

Joined: Dec 02, 2009
Posts: 3
Using Netbeans... When I run, everything is solid. When I clean and build the JAR and run, I'm having problems accessing files in the Jar file.



Just running, the result is TRUE.
Building JAR and running, the result is FALSE.

run command is: java -jar dist/myjar.jar

HELP!!!
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19541
    
  16

Just don't treat resources as files, because when inside a JAR, they aren't files - they are JAR entries (see JarFile and JarEntry). If you only need to read from the "file" use getResourceAsStream instead of trying to use File and FileInputStream. If you need to write to it you're simply out of luck.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Chris Merritt
Greenhorn

Joined: Dec 02, 2009
Posts: 3
I need to read, write, and hash file(s) that are in the JAR. So I'm outa luck I guess? I guess the alternative is a deployment/installation script that doesn't utilize a single JAR. Thanks for the info.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18114
    
    8

You can't write into a jar file, no. Often what people do is to provide a template, or default, file in the jar. If there are changes required to that, then they write it to a real file and use that from then on. Whether that fits into your requirements I can't tell.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Help! Accessing files in a JAR file at Runtime
 
Similar Threads
Jar app not running in Windows XP
List the files of a jar
Jar file accessing folder
Need help ,Urgent
Unable to access a file in my Jar file.