如何引用同一个jar中的资源/文件?

发布于 2024-11-29 23:15:17 字数 300 浏览 1 评论 0原文

我有一个 jar 文件,其中包含根目录中的两个文件
tbs.jar
-解析器.dat
-MapScript.txt
我尝试通过以下方式访问它们:
getClass().getResource("parser.dat")
我也尝试过:
getClass().getResource("/parser.dat")
但两者都不起作用。我正在使用的类(我称之为“getClass”的类)属于同一个 jar 中的包。那么我应该如何引用同一个 jar 中的文件,我应该尝试“../parser.dat”吗?我尝试的一切似乎都不起作用。

I have a jar file that contains two files in the root
tbs.jar
-parser.dat
-MapScript.txt
I've tried to access them with:
getClass().getResource("parser.dat")
and I also tried:
getClass().getResource("/parser.dat")
but neither works. The class that I'm using, the class I call "getClass" on, belongs to a package that lies in the same jar. So how am I supposed to refer to the files in the same jar, should I perhaps try "../parser.dat"? Nothing I try seems to work.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

音栖息无 2024-12-06 23:15:17

尝试替换

getClass().getResource("parser.dat") 

getClass().getClassLoader().getResource("parser.dat")

try replacing

getClass().getResource("parser.dat") 

with

getClass().getClassLoader().getResource("parser.dat")
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文