This week's book giveaway is in the General Computing forum.
We're giving away four copies of Arduino in Action and have Martin Evans, Joshua Noble, and Jordan Hochenbaum on-line!
See this thread for details.
The moose likes EJB and other Java EE Technologies and the fly likes Storing files in a jar Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Reply Bookmark "Storing files in a jar" Watch "Storing files in a jar" New topic
Author

Storing files in a jar

ravinderSingh singh
Ranch Hand

Joined: Nov 18, 2004
Posts: 41
When a file has been packaged within a JAR, how can you access it using a File or FileInputStream as you cannot specify the path ie. you can't do c:\\somefile.txt as the file in stored within a JAR?

Thanks
Pradeep bhatt
Ranch Hand

Joined: Feb 27, 2002
Posts: 8876

http://java.sun.com/j2se/1.3/docs/api/java/util/jar/JarInputStream.html


Groovy
ravinderSingh singh
Ranch Hand

Joined: Nov 18, 2004
Posts: 41
Thank you.

What do you do when both the class doing the reading and the file to be read are stored in the same JAR file? For example,

ClassOne.java - File which performs the read operation
README.txt - File to be read

Both are deployed in MyJar.jar
Pradeep bhatt
Ranch Hand

Joined: Feb 27, 2002
Posts: 8876

Originally posted by ravinderSingh singh:
Thank you.

What do you do when both the class doing the reading and the file to be read are stored in the same JAR file? For example,

ClassOne.java - File which performs the read operation
README.txt - File to be read

Both are deployed in MyJar.jar


I dont think it is possible to read a file in the same jar file.
:roll:
Sreenivasa Majji
Ranch Hand

Joined: Jul 12, 2001
Posts: 224
Yes. Its possible to keep the 'file' and the .class file in the same .jar file.


Sreenivasa Majji
Pradeep bhatt
Ranch Hand

Joined: Feb 27, 2002
Posts: 8876

Originally posted by Sreenivasa Majji:
Yes. Its possible to keep the 'file' and the .class file in the same .jar file.


This was not what the poster wants to know. He has already said that the file and .class are in the same jar. He wants to read the file from the .class without requiring the path to jar.
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: Storing files in a jar
 
Similar Threads
jar files question
Jar file issue
read content of text file which is in jar
XML Schema in a jar file?
getResource error when starting application in a jar file