• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

save properties file without affecting existing comments.

 
Krishnaa Kumar
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 212
1
Android Flex Google App Engine
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
what do you mean by lost? Are you using any editor to edit the key value pairs?
 
Matt Cartwright
Ranch Hand
Posts: 152
Linux VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Bartender
Posts: 1680
22
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Bartender
Posts: 1680
22
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My code...





 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic