title: Reading multiple resource from jar file
body: <p>I have jar file containing two folders each with a bunch of files (and possibly some other files in the root):</p>
  
  <pre><code>myjar.jar
   &gt; sub1
      &gt; file1.txt
      &gt; file2.txt
      &gt; file3.txt
      &gt; ...
   &gt; sub2
      &gt; file1.txt
      &gt; file2.txt
      &gt; file3.txt
      &gt; ...
   &gt; otherfile.txt
  </code></pre>
  
  <p>I have another project that depends on myjar.jar that contains an application that needs to read all the resources/text file and for each resource convert them into a string. Therefore I would like to do</p>
  
  <pre><code>URL url = this.class.getClassLoader().getResource("sub1");
  // Somehow iterate all sub urls and convert to string
  </code></pre>
  
  <p>Any good suggestion for doing this? One approach could be:</p>
  
  <pre><code>String scheme = url.getProtocol();
  if (!"jar".equals(scheme)) {
    // Hm who if we simply want to run from the workspace???
    throw new IllegalArgumentException("Unsupported scheme: " + scheme);
  }
  JarURLConnection con = (JarURLConnection) url.openConnection();
  JarFile archive = con.getJarFile();
  Enumeration&lt;JarEntry&gt; entries = archive.entries();
  while (entries.hasMoreElements()) {
    JarEntry entry = entries.nextElement();
    if (entry.getName().startsWith(folder)) {
      System.out.println(entry.getName());
    }
  }
  </code></pre>
  
  <p>but I would like to avoid this low-level code.</p>