通常我从 jar 文件中读取资源如下:
getClassLoader().getResource(pTextPath + "/" + pLang +".xml");
我需要从 jar 文件中的已知文件夹中读取具有特定名称的所有资源。例如。从
读取 *.xmladdon/resources/texts
我能否根据路径和名称模板以某种方式从 jar 文件中获取资源列表?
更新 Get a list of resources from classpath directory 的完全重复请关闭问题。
最佳答案
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... */
}
关于java - jar文件文件夹中的资源列表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7953600/