• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Java Property File

 
Francisco A Guimaraes
Ranch Hand
Posts: 182
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 java.sun.com and the Java Tutorial but didn�t find anything on this topic.
    Thanks,
    Francisco
     
    Joel McNary
    Bartender
    Posts: 1840
    Eclipse IDE Java Ruby
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    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
    DriveClass=sun.jdbc.odbc.JdbcOdbcDriver
    Password=pass_word
    UserName=web_user
    This is an example of a properties file specifying a Database connection.
    It is saved in the classpath with a .properties extension. (Say, as "MyDatabase.properties" 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.
     
    Francisco A Guimaraes
    Ranch Hand
    Posts: 182
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    What�s the difference between a property and a preference? why is the last one better? Can you give an example?
    Francisco
     
    Joel McNary
    Bartender
    Posts: 1840
    Eclipse IDE Java Ruby
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    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
    Greenhorn
    Posts: 7
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Hi,
    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.
    Sudheera
    [ May 27, 2003: Message edited by: Sudheera Liyanage ]
     
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic