• Post Reply Bookmark Topic Watch Topic
  • New Topic

Exception while accessing .properties file.  RSS feed

 
Rahul Ba
Ranch Hand
Posts: 212
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I amm stuck at one thing, I am trying to access .properties file through the simple java program which is standalone java program.

FileReader fReader = new FileReader("/config.properties");

It gives me null pointer exception as resource is not found.

1) I know .properties file should be in classes folder, but is there no any alternative to do this?


 
Sebastian Janisch
Ranch Hand
Posts: 1183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
new FileReader goes to your underlying OS, it does not start at the java app root dir.

Try using ClassLoader.getSystemResourceAsStream(name);

If you have a package like package1.package2.file.properties you would access it like this

 
Rahul Ba
Ranch Hand
Posts: 212
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ok, I think you gave me code snippet assuming y properties file is in classes...my question is is there any way to acess resource which is not in classes folder?
 
Sebastian Janisch
Ranch Hand
Posts: 1183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The regular I/O ... but you would need the absolute path.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!