Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

listing contents of jar file once its loaded into the local system

 
anirudh takkallapally
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I have a Config.jar file on the server, which contains xml files inside some subdirectories. When my applet gets loaded the config.jar file loads into my local machine and I can access the files from it using ClassName.class.getResourceAsStream(config\filename.xml);

Now the problem I have to list the entire contents of the config.jar file once I get it onto the local system. I tried something very lame like ClassName.class.getResourceAsStream(config), where config is the name of the directory, so that I could get the directory and once I have that, I could just list the contents of the directory, it didn�t work.

Is there a way of listing the contents once the jar file is loaded into JVM?

Thank you,
anirudh
 
Norm Radder
Bartender
Posts: 1355
14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes.
Look at the ZipFile class.
 
Norm Radder
Bartender
Posts: 1355
14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That depends what "loaded on the local system" means and what permissions the applet has.
If the jar is being controlled by the plugin, it's not really available outside of the JVM. I don't think there are any API that would be able to look at it. It doesn't really exist as a file for the running program. Its used by the JVM to locate resources such as classes.
If the jar file is on a local drive as a file, then ZipFile (with permission) can see it.
 
anirudh takkallapally
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the reply Norm, i am using URLClassLoader to load the config.jar file into JVM, dont have the jar file on the local file system. The only solution i could come up with is to have a file called directorylisting.xml in the jar file, this directorylisting.xml would contain the list of files and the directory structure inside the jar file and when i need to know the list of files i would just access the directorylisting.xml inside the jar file.

Please do let me know if you have an alternate solution.

thank you,
anirudh
 
Norm Radder
Bartender
Posts: 1355
14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That sounds like a good solution.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic