Problem accessing file from jar file in Java

早过忘川 提交于 2019-12-10 17:44:37

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!