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.
精彩评论