aspose file tools
The moose likes Java in General and the fly likes properties file location Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA Java SE 8 Programmer I Study Guide 1Z0-808 this week in the OCAJP forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "properties file location" Watch "properties file location" New topic
Author

properties file location

Paul Keohan
Ranch Hand

Joined: Mar 15, 2000
Posts: 411
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

Joined: Aug 20, 2001
Posts: 1824

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


Piscis Babelis est parvus, flavus, et hiridicus, et est probabiliter insolitissima raritas in toto mundo.
 
jQuery in Action, 2nd edition
 
subject: properties file location