问题
I have a jar called App.jar and it's structure is as follows
App.jar
|
|
|---xyzfolder
| |
| |--config
| |
| |--config.properties
|
|
|---com (contains classes)
|
|--MyClass.class
Now what I want is that I want to access config.properties
file from MyClass.class
回答1:
Have you tried the following?
this.getClass().getClassLoader().getResourceAsStream("classpath:/xyzfolder/config/config.properties");
see http://download.oracle.com/javase/1.5.0/docs/api/java/lang/ClassLoader.html#getSystemResourceAsStream%28java.lang.String%29
来源:https://stackoverflow.com/questions/5789667/problem-accessing-file-from-jar-file-in-java