3

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

2
  • 1
    I've tried getClassLoader().getResources("config.properties") which gives nullpointerexception error. Commented Apr 26, 2011 at 11:35
  • Thats because you need to specify the path. Its not in the same package Commented Apr 26, 2011 at 11:41

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.