开发者

How to refer to reasources/files in the same jar?

开发者 https://www.devze.com 2023-03-28 06:02 出处:网络
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:

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 开发者_StackOverflowI'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.


try replacing

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

with

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

精彩评论

暂无评论...
验证码 换一张
取 消