File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes Problem in replacing key/value pair in properties file Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "Problem in replacing key/value pair in properties file" Watch "Problem in replacing key/value pair in properties file" New topic
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.
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: Problem in replacing key/value pair in properties file
 
Similar Threads
how to use the .prp file
Properties File in Struts
How to generate XML from MAP
Default Language Properties file
Help understanding what is written to configuration file and who writes what.