7

As usually I read resources from jar file as following:

getClassLoader().getResource(pTextPath + "/" + pLang +".xml");

I need to read all resources with certain name from known folder in jar file. E.g. read *.xml from

addon/resources/texts

Could I somehow get from jar files list of resources according to path and name template?

UPDATE: Exact duplication of Get a list of resources from classpath directory Please close the question.

Community
  • 1
  • 1
FoxyBOA
  • 5,788
  • 8
  • 48
  • 82

1 Answers1

4
CodeSource src = MyClass.class.getProtectionDomain().getCodeSource();
if (src != null) {
  URL jar = src.getLocation();
ZipInputStream zip = new ZipInputStream(jar.openStream());
/* Now examine the ZIP file entries to find those you care about. */
 ...
} 
else {
   /* Fail... */
}
vikas27
  • 563
  • 5
  • 14
  • 36
  • 1
    `else { /* Fail... */` At what point does the code handle the `SeurityException` potentially thrown by [`Class.getProtectionDomain()`](http://download.oracle.com/javase/7/docs/api/java/lang/Class.html#getProtectionDomain%28%29)? – Andrew Thompson Oct 31 '11 at 14:26