This week's book giveaway is in the Agile and other Processes forum.
We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line!
See this thread for details.
The moose likes Java in General and the fly likes Properties file value change Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "Properties file value change" Watch "Properties file value change" New topic
Author

Properties file value change

jaisai vijay
Ranch Hand

Joined: Dec 17, 2009
Posts: 70
Hi,

I have a situation where I need to change the value of properties file after the successful execution of a program.

I have a filename called myProperties.properties here I have value process.time='03/24/2010' and I have few other values in this property file. What I need to do is change the process.time value after successful execution of a program with out touching other values.

Thanks for your help in advance.
Wouter Oet
Saloon Keeper

Joined: Oct 25, 2008
Posts: 2700

Just read the file into a Properties object, update the property and write it to a file.


"Any fool can write code that a computer can understand. Good programmers write code that humans can understand." --- Martin Fowler
Please correct my English.
jaisai vijay
Ranch Hand

Joined: Dec 17, 2009
Posts: 70
I tried in the following way



The problem is I have some format in the actual file when write the content using ouputstream I lost my format.

Thanks for your help.
Wouter Oet
Saloon Keeper

Joined: Oct 25, 2008
Posts: 2700

That's correct. You'll lose the format but the data is the same.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

You could also do it manually. Or you could store that property in a completely separate file and reduce the risk of trashing your properties file. Or put it in a DB, which is where often-changed values really belong, IMO.
Wouter Oet
Saloon Keeper

Joined: Oct 25, 2008
Posts: 2700

I agree but 1 change at the end of the program is not much. I don't think a DB is the solution because then people can't easily read the content and I'm assuming that's what the poster wants because otherwise we wouldn't mind that the format gets ruined.
jaisai vijay
Ranch Hand

Joined: Dec 17, 2009
Posts: 70
Hi,

Thanks for your help guys. As per the replies I have created another properties file and always I update this file only.

Thanks
Have a Good day.
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: Properties file value change
 
Similar Threads
Configure custom properties of a Datasource in WebSphere 7 after creating it with Jython scripts
reloading properties file from database in struts
Configuration files - Best Practice?
edit properties file
Properties file