Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

properties file location

 
Paul Keohan
Ranch Hand
Posts: 411
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is there a way to find a properties file from a class no matter where it is on the disk? I know you can use a getProperty() method to find the jdk ext directory and I could put my properties file there. I have a properties file which holds locations of other files. It would seem I'd need a properties file to hold the location of the properties file, and another properties file to hold the location of that properties file and so on . . .
I'd like to just name the file in the class, and not worry about which directory it's located in.
Thanks.
Paul
 
Joel McNary
Bartender
Posts: 1840
Eclipse IDE Java Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Depends on how flexible you want to be. You could use the java.io.File class to walk the directory structure of the disk looking for the file, but I don't recommend that
Instead, I just put my properties in classpath and don't worry about the directory. Loading the Properties through PropertyResourceBundle.getBundle("myPropertiesFile") uses the classpath, so as long as my file is in the classpath I don't worry about it. If I don't have a resource in the classpath, I don't have the resource.
(Of course, I'm looking at moving to Preferences anyway...)
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic