I have a .properties file which have number of comments in it, when I try to update the content of the file other than the comments, even though my comments are disappearing, how to retain my comments?
Here is the config.properties file:
#name of user
name=user1
#id of user
id=id1
and the code to update the properties file, I used
public class SetLog {
public static void setPath()
{
File file = new File("./config.properties");
Properties prop = new Properties();
FileInputStream objInput = null;
try {
objInput = new FileInputStream(file);
prop.load(objInput);
objInput.close();
FileOutputStream out = new FileOutputStream("./config.properties");
//update the content
prop.setProperty("name", "user2");
prop.store(out, null);
out.close();
} catch (Exception e) {}
}
}
After I run the above code, properties file content changed to:
name=user2
id=id1
But I want in this format:
#name of user
name=user2
#id of user
id=id1
How to retain my comments, please help!