| Author |
Problem in replacing key/value pair in properties file
|
Kathiresan Chinnasamy
Ranch Hand
Joined: Jan 01, 2008
Posts: 65
|
|
Hi Friends, My Problem is : If i replace any value for corresponding key, its replaces fine and the same way , its remove all (#)comment files. How Can i resolve this problem: for Example: The Existing Properties file contains: # comment 1 one = 1 # comment 2 two = 2 After Replacing the key of one #comment 1 # time Stamp one = hi two = 2 Here its removes the # comment 2 but i want to retain that too If any body know, help me Thanks in advance
|
 |
Jesus Angeles
Ranch Hand
Joined: Feb 26, 2005
Posts: 2036
|
|
How are you editing it? Are you doing it programmatically? Or are you using a text editor? Or an IDE?
|
 |
Kathiresan Chinnasamy
Ranch Hand
Joined: Jan 01, 2008
Posts: 65
|
|
i am putting here what i done FileInputStream in = new FileInputStream("sample.properties"); defaultproperties.load(in); System.out.println(defaultproperties.clone()); defaultproperties.setProperty(replceKeyVal, result); FileOutputStream os = new FileOutputStream("sample.properties"); defaultproperties.store(os,"Comment 1");
|
 |
Jesus Angeles
Ranch Hand
Joined: Feb 26, 2005
Posts: 2036
|
|
Refer to this http://java.sun.com/j2se/1.5.0/docs/api/java/util/Properties.html. The .store method writes a comment on the first line. The second line would be, as you showed, a date/time data The third line up to the last line, are the contents of the properties. In the link above, no other comments are mentioned to be writeable anywhere else, other than the first 2 lines. You can use an xml properties file, for better comment-capability. Refer to the same link above. Look at methods like .storeToXml.
|
 |
 |
|
|
subject: Problem in replacing key/value pair in properties file
|
|
|