由於平時我讀jar文件資源如下:jar文件的文件夾中的資源列表?
getClassLoader().getResource(pTextPath + "/" + pLang +".xml");
我需要從jar文件夾稱爲特定名稱來讀取的所有資源。例如。閱讀*從
插件/資源/文本
的.xml我能以某種方式根據路徑和名稱模板從資源的jar文件的列表得到什麼?
更新:完全重複Get a list of resources from classpath directory請關閉此問題。
由於平時我讀jar文件資源如下:jar文件的文件夾中的資源列表?
getClassLoader().getResource(pTextPath + "/" + pLang +".xml");
我需要從jar文件夾稱爲特定名稱來讀取的所有資源。例如。閱讀*從
插件/資源/文本
的.xml我能以某種方式根據路徑和名稱模板從資源的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... */
}
'else {/ *失敗... * /'代碼在什麼時候處理' ['Class.getProtectionDomain()'](http://download.oracle.com/javase/7/docs/api/java/lang/Class.html#getProtectionDomain%28%29)可能拋出SeurityException異常? –
在Jar生成時列出一個列表。在運行時閱讀該列表。 –
http://stackoverflow.com/questions/3923129/get-a-list-of-resources-from-classpath-directory –