I have this code which reads all the files from a directory.
File textFolder = new File("text_directory");
File [] texFiles = textFolder.listFiles( new FileFilter() {
public boolean accept( File file ) {
return file.getName().endsWith(".txt");
}
});
Works great. It fills the array with all the files that end with ".txt" from directory "text_directory"
Question:
How can I read in a similar fashion the contents of a directory within a jar file?
So what I really want to do is list in a similar fashion all the images inside my jar, so I can load them with:
ImageIO.read(this.getClass().getResource("CompanyLogo.png"));
That one works because the "CompanyLogo" is "hardcoded" but the number of images inside the jar could be from 10 to 200.
EDIT
So I guess my main problem would be, how to know the name of the jar where my main class lives.
Granted I could read it using java.util.Zip
My Structure is like this:
They are like:
my.jar!/Main.class my.jar!/Aux.class my.jar!/Other.class my.jar!/images/image01.png my.jar!/images/image02a.png my.jar!/images/imwge034.png my.jar!/images/imagAe01q.png my.jar!/META-INF/manifest
Right now I'm able to load for instance "images/image01.png" using:
ImageIO.read(this.getClass().getResource("images/image01.png));
But only because I know the file name, for the rest I have to load them dinamically.
Thanks in advance.