jar文件夹中的资源列表? [英] List of resources in a folder of jar file?

查看:336
本文介绍了jar文件夹中的资源列表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

As usually I read resources from jar file as following:

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

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

I need to read all resources with certain name from known folder in jar file. E.g. read *.xml from


addon / resources / texts

addon/resources/texts

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

Could I somehow get from jar files list of resources according to path and name template?

更新: <的完全重复< a href =https://stackoverflow.com/questions/3923129/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... */
}

这篇关于jar文件夹中的资源列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆