Add comments to the properties file line by line

This is what I want to do in the properties file

#Comments about key Value pair 1
Key_1=value_1


#Comments about key Value pair 2
Key_2=value_2

#Comments about key Value pair 3
Key_3=value_3

Now i can do with my file

#OMG, It works!
#Mon Oct 14 01:22:10 IST 2013
Key_1=Value_1
Key_2=Value_2

Is there any way to do such a thing

+4
source share
3 answers

You can use the Apache Commons Configuration to write and read property files, specifically setComment () in the PropertiesConfigurationLayout , which allows you to specify a comment for each property.

Please note that the links above refer to Commons Configuration v1.x, while v2.0 was released in the meantime, which has different package names.

+4
source

, , Properties.

, , , . , , = : . , , , , , <key>⇒<value,comment>, .

+1

I think that basically you want a property with a comment with a description. If so, then

Properties props=new Properties();
props.add("key","value");
FileOutputStream output=new FileOutputStream("props.dat",true); //so that it won't create a new file since it is 'true')
 props.store(output,"Sample properties"); 
0
source

All Articles