List of resources in a folder of jar file?

北城以北 提交于 2019-12-19 17:45:55

问题


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.


回答1:


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


来源:https://stackoverflow.com/questions/7953600/list-of-resources-in-a-folder-of-jar-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!