FoxyBOA
FoxyBOA

Reputation: 5846

List of resources in a folder of jar file?

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.

Upvotes: 7

Views: 7548

Answers (1)

vikas27
vikas27

Reputation: 573

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... */
}

Upvotes: 4

Related Questions