开发者

problem loading .properties file in java

开发者 https://www.devze.com 2023-01-19 00:44 出处:网络
I am having problem while loading .properties file. The f开发者_StackOverflowollowing works: private static Properties props = new Properties();

I am having problem while loading .properties file. The f开发者_StackOverflowollowing 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.


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()


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

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号