Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do I list the files inside a JAR file?
    primarykey
    data
    text
    <p>I have this code which reads all the files from a directory.</p> <pre><code> File textFolder = new File("text_directory"); File [] texFiles = textFolder.listFiles( new FileFilter() { public boolean accept( File file ) { return file.getName().endsWith(".txt"); } }); </code></pre> <p>It works great. It fills the array with all the files that end with ".txt" from directory "text_directory".</p> <p>How can I read the contents of a directory in a similar fashion <strong>within</strong> a JAR file? </p> <p>So what I really want to do is, to list all the images inside my JAR file, so I can load them with: </p> <pre><code>ImageIO.read(this.getClass().getResource("CompanyLogo.png")); </code></pre> <p>(That one works because the "CompanyLogo" is "hardcoded" but the number of images inside the JAR file could be from 10 to 200 variable length.) </p> <p><strong>EDIT</strong></p> <p>So I guess my main problem would be: How to know the <strong>name of the JAR file</strong> where my main class lives?</p> <p>Granted I could read it using <code>java.util.Zip</code>.</p> <p>My Structure is like this:</p> <p>They are like:</p> <pre><code>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 </code></pre> <p>Right now I'm able to load for instance "images/image01.png" using: </p> <pre><code> ImageIO.read(this.getClass().getResource("images/image01.png)); </code></pre> <p>But only because I know the file name, for the rest I have to load them dynamically.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload