jQuery in Action, 3rd edition
The moose likes I/O and Streams and the fly likes setting values in properties file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "setting values in properties file" Watch "setting values in properties file" New topic

setting values in properties file

r kh

Joined: Feb 23, 2013
Posts: 3
I am trying to update a value in property file through the following code

Output: updated

But the values doesn't seem to get updated. In Fact, I am not getting any error even if the property or the file itself is not present.
T Mishra
Ranch Hand

Joined: Apr 04, 2006
Posts: 108

I think, the stream must be closed before setting/updating value. Try this

Tushar (SCJP 1.5)
Alexander Bondarev

Joined: Jan 04, 2012
Posts: 12
You actually deal with two files with the same name. One is located in the CLASSPATH. The class loader reads it in the method getResourceAsStream("myfile.properties"). The second file is created in the current working directory by the constructor FileOutputStream("myfile.properties"). The first file isn't updated because the value is changed in the second file.
r kh

Joined: Feb 23, 2013
Posts: 3
Yup, That's what happening! It works fine if I use OutputStream and InputStream everywhere.
I agree. Here's the link: http://aspose.com/file-tools
subject: setting values in properties file
It's not a secret anymore!