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?
posted 11 years ago
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.