Reputation: 5846
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
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