File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java in General and the fly likes Modifying Property Files. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Modifying Property Files." Watch "Modifying Property Files." New topic

Modifying Property Files.

Nikhil Jain
Ranch Hand

Joined: May 15, 2005
Posts: 389
Can property file be modified programatically?

SCJP 1.4, SCWCD 1.4, SCBCD 1.5, TOGAF 9, Comptia Cloud+
Sudarshan Chakrabarty
Ranch Hand

Joined: Apr 10, 2008
Posts: 38
Well a Property file is just a text file after all. Just as you can read from a property file so can you write to a property file.
You can always modify a file using the FileWriter programatically.
arulk pillai
Ranch Hand

Joined: May 31, 2007
Posts: 3371
But once you programmatically modify it, need to reload the data to your memory (e.g. Properties) for those changes to take effect or need to restart the application.

[] | [Java job hunting know how] | [Java resumes]
Gamini Sirisena
Ranch Hand

Joined: Aug 05, 2008
Posts: 378
Yes you can use the Properties class to load and store a property file.

look at the load and store methods of this class. The properties class is basically a Hashtable and you can put and remove elements from it.

The only problem might be that you will lose any comments already in the property file. I believe the Jakarta Commons project has an implementation that supports comments.
I agree. Here's the link:
subject: Modifying Property Files.
It's not a secret anymore!