• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Problem in replacing key/value pair in properties file

 
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 2108
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How are you editing it?

Are you doing it programmatically?

Or are you using a text editor?

Or an IDE?
 
Kathiresan Chinnasamy
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 2108
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic