如何引用同一个jar中的资源/文件?
我有一个 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技术交流群](/public/img/jiaqun_03.jpg)
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试替换
为
try replacing
with