• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Reading a textfile stored in an jar archiv

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How can I read a textfile that is stored in the same jar-archiv as the main class?
My application reads some data out of a textfile, now I put all class-files and this textfile in an executable jar-archiv. But I don�t know how to address the textfile in the archiv. I still have to access a copy of the textfile, that is stored outside the archiv.
Regards, Dirk.
[ January 22, 2002: Message edited by: Dirk Mohr ]
 
Ranch Hand
Posts: 349
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think (but not sure) that ZipInputStream and ZipOutputStream classes can do the needful.
Check them out.
Rashid Ali
 
Ranch Hand
Posts: 125
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You need to read the text file as a system resource.
See:
http://java.sun.com/j2se/1.3/docs/guide/resources/
Programs can accesses resources such as images, propery files, help documents, and web pages that are stored in a jar file along with the program.
 
Dirk Mohr
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Rashid,
the ZipInputStream class is not the thing I was looking for. Nevertheless, thanks a lot!
 
Dirk Mohr
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Steve, you hit the mark.
My jar has the following structure:
MyJar.jar
\MainClass
\SomeOtherClasses\...
\SomeBasicData\foo.txt
Now I use:

to read the data stored in foo.txt - works fine.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic