• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Reading a text file from a jar file?

 
Ranch Hand
Posts: 305
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Everybody,
Ok I think it is now the appropriate time to ask this questions after all my trials.
I have a jar file which has following types of files:
File name Directory Structure
test.class /
makePanel.class /test
pic1.gif /images/pic
pic2 /images
abc.ict /
xyz.id /images/pic
where xyz.id and abc.ict are simple text files with a change in extension. Now problem is in extracting it... As the documentation goes that I have to use ClassLoader to load same before using.. I tried the following:
For Images:

It works.
2. Now problem comes in when I want to read all the files from the directory /image/pic.. In a normal case I was trying the following code snippet...

but failed to retrieve same from jar file with the above concept.
if i tried with:

It doesn't work...perhaps the path it is giving is:
jar:file:/E:/test/test.jar!/images/pic
Can somebody help me in this regard...

regards,
arun
 
arun mahajan
Ranch Hand
Posts: 305
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In a desperate attemp I tried with another set of codes:

Here in above the InputStream object in is null...while all other has some value..
I think I am somewhere missing the concept badly of jar files..can somebody help me...
regards,
arun
 
mister krabs
Posts: 13974
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why can't you use JarInputStream?
 
arun mahajan
Ranch Hand
Posts: 305
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Thomas for your answer and I tried with following code but again in vain...again NullPointerException...Any more idea?

regards,
Arun
 
Thomas Paul
mister krabs
Posts: 13974
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How about showing the actual error? Where are you getting the NullPointerException?
 
arun mahajan
Ranch Hand
Posts: 305
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Oops I got yhe answer for it at last..Special thanks to Thomas who has given me a lead..
posting the code snippet if some one is interested !!



regards,
Arun
 
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well done, Arun, and thanks for sharing what you learned.
 
Acetylsalicylic acid is aspirin. This could be handy too:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic