File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes Java Property File Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Java Property File" Watch "Java Property File" New topic

Java Property File

Francisco A Guimaraes
Ranch Hand

Joined: Mar 20, 2002
Posts: 182
How do I use a property file?
  • how do I write it?
  • where do I save it?
  • how do I use its properties inside a class?

  • I searched a bit in and the Java Tutorial but didn�t find anything on this topic.

    Francisco<br />SCJP<br />please use the [code][/code] tags when showing code.Click <a href="" target="_blank" rel="nofollow">here</a> to see an example.
    Joel McNary

    Joined: Aug 20, 2001
    Posts: 1824

    Properties are passe; Preferences are the current rage. That said, properties are still useful for quick-and-easy settings.
    Basically, a Properties file contains key/value associations:
    ConnectionURL=jdbc dbc:MyDatabase
    This is an example of a properties file specifying a Database connection.
    It is saved in the classpath with a .properties extension. (Say, as "" in the "mypackage" package.)
    You use it by using the java.util.(Property)ResourceBundle class

    Of course, you can do other things with it as well. See the java.util.PropertyResourceBundle documentation for more information.

    Piscis Babelis est parvus, flavus, et hiridicus, et est probabiliter insolitissima raritas in toto mundo.
    Francisco A Guimaraes
    Ranch Hand

    Joined: Mar 20, 2002
    Posts: 182
    What�s the difference between a property and a preference? why is the last one better? Can you give an example?
    Joel McNary

    Joined: Aug 20, 2001
    Posts: 1824

    Unfortunately, I've not had the time to really get into the Preferences API, so my code still uses Properties. In the coming months I'll get around to making the switch (I've wrapped the Properties API anyway, so switching to Preferences should (hopefully) noe be that big a deal.)
    However, you can read Thomas Paul's newsletter article on the subject.
    [ May 27, 2003: Message edited by: Joel McNary ]
    Sudheera Liyanage

    Joined: Oct 14, 2002
    Posts: 7
    I am developing some java classes(APIs) which will be used by other developers in there applications.
    I use a property file to store application dependant values. ex:log file path name.
    I have put the .propertie file to same folder where my class file exists. In command prompt
    my class is running without problem. But when I use my IDE (Eclipse 2), it does not work(it cannot fine the file)).
    I have added the properties file to system classpath, it also not work.
    Please help me.
    [ May 27, 2003: Message edited by: Sudheera Liyanage ]
    I agree. Here's the link:
    subject: Java Property File
    It's not a secret anymore!