0

I am having problem while loading .properties file. The following works:

private static Properties props = new Properties();
 ................
 .......................
 configurationProps.load(Test.class.getResourceAsStream("test.properties"));

But this;

private static Properties props = new Properties();
 ................
 .......................
 configurationProps.load(Test.class.getResourceAsStream("C:\\someFilder\\test.properties"));

gives the following error.

Exception in thread "main" java.lang.NullPointerException
 at java.util.Properties.load(Properties.java:267)
 at Test.init(Test.java:24)
 at Test.main(Test.java:16)

I am wondering why its not taking full path. Any suggestion is highly appreciated.

2 Answers 2

5

Try

configurationProps.load(new FileInputStream("C:\\..."));

Using getResourceAsStream delegates to the ClassLoader and thus typically only works relative to the classpath. The rules for where it searches are given in the Javadoc for getResource()

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

Comments

-2
private static Properties props = new Properties();
 ................
 .......................
 configurationProps.load(Test.class.getResourceAsStream("../../../../../../../../../../../../../../../../../../../../C:\\someFilder\\test.properties"));

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.