| Author |
save properties file without affecting existing comments.
|
Krishnaa Kumar
Greenhorn
Joined: May 05, 2011
Posts: 25
|
|
Hi,
I have a properties file filled up with comments about the key value pair, followed by key value pair.
If, i edit the some key values and save the file, all my comments are lost.
Is there any way to save the new key values with original comments.
-Krishna
|
 |
Sai Hegde
security forum advocate
Ranch Hand
Joined: Oct 26, 2010
Posts: 183
|
|
what do you mean by lost? Are you using any editor to edit the key value pairs?
|
 |
Matt Cartwright
Ranch Hand
Joined: Aug 25, 2008
Posts: 149
|
|
There are no methods on java.util.Properties to handle comments.
They are simply ignored when reading the file.
A comment (one per file) can only be added when using store(...) or storeToXML(...).
You would need to implement a class that reads the file line by line and stores these
lines in the correct order.
The NvPs the need to go into some HashTable...
I think you get the picture.
HTH
Matt
|
 |
Carey Brown
Ranch Hand
Joined: Nov 19, 2001
Posts: 159
|
|
|
I think that the OP is referring to the store() method which writes a file in (probably) hash order and drops any of the original comments. I ended up writing my own Properties work-alike class using a LinkedHashMap to get around this issue.
|
 |
Carey Brown
Ranch Hand
Joined: Nov 19, 2001
Posts: 159
|
|
My code...
|
 |
 |
|
|
subject: save properties file without affecting existing comments.
|
|
|