aspose file tools*
The moose likes Java in General and the fly likes Listing files in a JAR?? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Listing files in a JAR??" Watch "Listing files in a JAR??" New topic
Author

Listing files in a JAR??

David Kromek
Greenhorn

Joined: Feb 27, 2005
Posts: 2
Hi,

I have a couple of queries:

I have an executable .jar file that contains a single directory called "App". This directory contains the entire application including a number of subdirectories, one of which is called "images". I want to obtain a list of all the files contained in "images", but I'm not quite sure how to do this. I'm aware that ClassLoader.getSystemResource("App/images/" + filename) will return an URL to any particular file in the jar. But I've tried using ClassLoader.getSystemResources() (which is supposed to return an enumeration) without success. I've tried ClassLoader.getSystemResources("App/images/*") but this doesn't return anything. What am I doing wrong?

Also, my java program loads about 250 jpeg files as ImageIcons. The total amount of memory these files occupy is just under 2.5 MB. But I find that I need to set the java executor's heap memory to about 60 MB (using the switch -Xmx60MB) in order to load these files without getting a number of out of memory exceptions. Why do I need to do this? Why is java so resource hungry?


David.
Jonas Isberg
Ranch Hand

Joined: Mar 18, 2003
Posts: 118
I tried solving your problem of getting the names of all the files in a
certain directory in a jar file by using the java.util.jar package.

The solutions is not very elegant. The program opens the jar file, checks if the given directory really exists and really is a directory and then does a string comparision to see which entries are located in the given directory.

Hope it will guide you towards solving your problem.


[ March 24, 2005: Message edited by: J Isberg ]
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Listing files in a JAR??