Hi there,
I notice that when we try to write a value back to the property file,
the original comment in the property file will be removed.
Any idea how to keep the comment in the property file and yet updating
the key with the new value?
String filename = "property.properties";
Properties p = new Properties();
p.setProperty("CacSrv", "SomeValue");
p.store(new FileOutputStream(filename), null);
Robert Klemme - 15 Dec 2006 10:48 GMT
> Hi there,
>
> I notice that when we try to write a value back to the property file,
> the original comment in the property file will be removed.
> Any idea how to keep the comment in the property file and yet updating
> the key with the new value?
I believe you will have to parse the file yourself to extract the
comment. Alternatively you could use an unused key for the comment.
> String filename = "property.properties";
> Properties p = new Properties();
> p.setProperty("CacSrv", "SomeValue");
> p.store(new FileOutputStream(filename), null);
You do not close the FileOutputStream properly. This costs resources
and also might cause inconsistent file content.
robert
Flo 'Irian' Schaetz - 15 Dec 2006 17:19 GMT
And thus, vincente13@gmail.com spoke...
> p.store(new FileOutputStream(filename), null);
You are setting your header to null. So the properties don't have a
header... If you want text there, put it there instead of null.
Flo