• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to create a properties file?

 
Sean Gildea
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

I've searched all over these forums regarding creating a properties file if one does not exist, and many of the threads suggest a resourcebundle and a fileinputstream, but do not offer clear specifics.

My question is, how do you create a properties file if one does not exist?

Code examples would be perfect.

Thanks!
 
Inuka Vincit
Ranch Hand
Posts: 175
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is a java properties object that you can use
http://java.sun.com/j2se/1.3/docs/api/java/util/Properties.html

I resorted to using simple file streams and not using properties. Its totally upto you. I save database location and connection, so the file wasnt complicated.
 
peter wooster
Ranch Hand
Posts: 1033
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Sean Gildea:
Hi all,

I've searched all over these forums regarding creating a properties file if one does not exist, and many of the threads suggest a resourcebundle and a fileinputstream, but do not offer clear specifics.

My question is, how do you create a properties file if one does not exist?

Code examples would be perfect.

Thanks!


Create a java.util.Properties object, put the properties in that object, define a FileOutputStream on "suncertify.properties" and the use the Properties.store method to write it. eg.


You can read it from a FileInputStream using Properties.load.
 
Sean Gildea
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Nick!

Works great!


[ November 23, 2004: Message edited by: Sean Gildea ]
 
MF Tang
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Don't forget to add a GUI to configure the properties
It's a MUST stated in the requirement. That took me quite some time.

MF Tang
SCJP, SCJD (in progress)
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic