• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

Reading files in a directory of the jar file  RSS feed

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I've created an applet and I'm running it from a browser accessing a jar file.

I can read the contents of a file using getClass().getResourceAsStream(nameofthefile) but I want to read the contents of all the files in a subdirectory of the jar so I don't have the file names.

Is there any way I could find all the file names in this subdirectory of the jar.

Thanks, and sorry for the poor english.
 
Rancher
Posts: 42975
76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can't you create a JarInputStream from the InputStream returned by getResourceAsStream, and then deal with the files by using the methods of JarInputStream?
 
Andr� Jesus
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks, it worked fine once I've opened the jar file, but when I open the applet on the browser I get an Exception.

This is the code:
URL url = new URL("http://localhost:8080/.../myfile.jar");.
I get an AccessControlException

I am trying to read files in the same jarfile the applet is running in. Is there any problems in opening this file again (the applet is already runnig in the browser)?
 
Ulf Dittmer
Rancher
Posts: 42975
76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do you run the applet off the localhost web server, or directly from the file system, i.e. does the browser URL field say "http://localhost..." or "file:///..."?
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!