简体   繁体   中英

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. Eg 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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM