gpt4 book ai didi

java - jar文件文件夹中的资源列表?

转载 作者:塔克拉玛干 更新时间:2023-11-03 05:22:52 28 4
gpt4 key购买 nike

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

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

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

读取 *.xml

addon/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/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com