开发者

Load a file that's been bundled within the .jar?

I'm building a project with ant and during the build I'd like to bundle a number of property/config files directl开发者_JAVA百科y into the .jar to make distribution simpler. I've been successful in adding these files to the .jar, but I'm unable to load them in my program.

What is the procedure to open/read a file that's been bundled into a .jar file?


Use the getResourceAsStream method on class:

Properties p = new Properties();
p.load(MyClass.class.getResourceAsStream("/myprops.properties"));


You can load those by using the ClassLoader getResourceAsStream() method.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜