access file from jar file

B

Bruintje Beer

Hello,

I have a jar file which have files in it like

nl.company.data.file1
nl.company.data.file2

and build in data.jar

In another java program I want to access these files and read the content
from the jar file 'data.jar'

How do I do that

thanks

John
 
M

Mike Schilling

Bruintje said:
Hello,

I have a jar file which have files in it like

nl.company.data.file1
nl.company.data.file2

and build in data.jar

In another java program I want to access these files and read the
content from the jar file 'data.jar'

How do I do that


Files in the class path and in particular in jar files in the class
path are called "resources" in java. Look up Class.getResource() and
ClassLoader.getResource().
 
R

Roedy Green

In another java program I want to access these files and read the content
from the jar file 'data.jar'

You read with a resource. If you have a nested jar, you have to
unpack the jar and then read it as a file. Alternatively, you unpack
the jar so there is one big jar with no nesting. Then you get at
everything as a resource.

See http://mindprod.com/jgloss/resource.html
http://mindprod.com/jgloss/image.html (lots of example code to fish
out resources.)
--
Roedy Green Canadian Mind Products
http://mindprod.com

"Deer hunting would be fine sport, if only the deer had guns."
~ William S. Gilbert of Gilbert and Sullivan
 
B

Bruintje Beer

Mike Schilling said:
Files in the class path and in particular in jar files in the class path
are called "resources" in java. Look up Class.getResource() and
ClassLoader.getResource().

thanks, it works
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,236
Members
46,825
Latest member
VernonQuy6

Latest Threads

Top