File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JDBC and Relational Databases and the fly likes location of a property file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "location of a property file" Watch "location of a property file" New topic

location of a property file

Annette L'Heureux
Ranch Hand

Joined: Dec 07, 2000
Posts: 135
I just can't seem to get this darn thing working!
I have a .properties file that I created, and I wasn't sure where to put it so I put it in the folder where I keep my regular html files. I did this because I need to be able to call it, and I figured I could just do this:
With my regular html files, anything after the "/" is looked for in this particular folder. Right?
Is this what's supposed to be done? Why can't anything be read off the file?
Thanks again,
Thomas Paul
mister krabs
Ranch Hand

Joined: May 05, 2000
Posts: 13974
Are you talking about the file in the program sample that I gave you? If so, that can go in any directory but you must pass in that directory when you invoke the connectToDatabase() method.

Associate Instructor - Hofstra University
Amazon Top 750 reviewer - Blog - Unresolved References - Book Review Blog
Nick Heudecker
Ranch Hand

Joined: Jul 09, 2000
Posts: 52
Not too sure what the problem is, but this is a method I use often to load a properties file from the filesystem:

It can obviously be improved, but as long as the directory that contains the properties file is a directory listed in your classpath, you application will be able to find it.

---<br />Co-author of "Hibernate Quickly"<br /><a href="" target="_blank" rel="nofollow"></a>
Bhupinder Dhillon
Ranch Hand

Joined: Oct 12, 2000
Posts: 124
This one ticked me off for a long time until I finally read it in
java spec., I think! If you just want to get a list of properties
in the file and use it somewhere in your java program then why don't you use java.util.ResourceBundle? It's much more convenient and easy to use.
If is a top class (not in a package):
ResourceBundle rb = ResourceBundle.getBundle(">);
If is in the same package as the class accessing it:
ResourceBundle rb = ResourceBundle.getBundle(">);
If is in a package named com.mypackage and you are accessing it from some other package:
ResourceBundle rb = ResourceBundle.getBundle("com/mypackage/>);
To get a property:
String propValue = rb.getString("propertyName");
Much more easier, ain't it?
Peter den Haan
Ranch Hand

Joined: Apr 20, 2000
Posts: 3252
Originally posted by Nick Heudecker:
Not too sure what the problem is, but this is a method I use often to load a properties file from the filesystem:

If this properties file is part of a J2EE web-app then Servlet.getServletConfig().getServletContext().getResource*() is more appropriate, I think.
- Peter

subject: location of a property file
It's not a secret anymore!