【问题标题】:List of resources in a folder of jar file?jar文件文件夹中的资源列表?
【发布时间】:2011-12-18 17:02:48
【问题描述】:

通常我从 jar 文件中读取资源如下:

getClassLoader().getResource(pTextPath + "/" + pLang +".xml");

我需要从 jar 文件中的已知文件夹中读取具有特定名称的所有资源。例如。从

读取 *.xml

插件/资源/文本

我可以根据路径和名称模板以某种方式从 jar 文件中获取资源列表吗?

更新:Get a list of resources from classpath directory 的确切重复请关闭问题。

【问题讨论】:

标签: java tomcat servlets resources jar


【解决方案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... */
}

【讨论】:

猜你喜欢
  • 1970-01-01
  • 2020-05-27
  • 1970-01-01
  • 2012-12-07
  • 2016-12-28
  • 2011-09-17
  • 1970-01-01
  • 2012-06-16
相关资源
最近更新 更多