Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

location of properties file  RSS feed

 
arushi tomar
Ranch Hand
Posts: 91
3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What should be the location of properties file? I am getting this exception when the file is in the same package as the class :
Exception in thread "main" java.io.FileNotFoundException: db.properties (The system cannot find the file specified)

and what is the proper code to read from properties file?

I used this :

and at last line i got null pointer exception.
 
Stephan van Hulst
Saloon Keeper
Posts: 7806
142
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why are you using the context class loader? Use the current class directly:
 
Rob Spoor
Sheriff
Posts: 21090
85
Chrome Eclipse IDE Java Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you use a ClassLoader to load resources, the path is relative to the root of the class path, not relative to the class. Use Stephan's code to read resources relative to the class.
 
arushi tomar
Ranch Hand
Posts: 91
3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you. It works perfectly. :-)
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!