f



access file from jar file

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 


0
me3001 (2)
6/28/2009 6:52:40 AM
comp.lang.java.programmer 52714 articles. 1 followers. Post Follow

3 Replies
627 Views

Similar Articles

[PageSpeed] 22

Bruintje Beer wrote:
> 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(). 


0
6/28/2009 7:02:07 AM
On Sun, 28 Jun 2009 08:52:40 +0200, "Bruintje Beer" <me@me.nl> wrote,
quoted or indirectly quoted someone who said :

>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
0
see_website (5876)
6/28/2009 7:38:51 AM
"Mike Schilling" <mscottschilling@hotmail.com> schreef in bericht 
news:h274md$ni9$1@news.eternal-september.org...
> Bruintje Beer wrote:
>> 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().
>

thanks, it works



0
me3001 (2)
6/28/2009 7:46:18 AM
Reply: