I wish to change a property value inside a property file. I tried some ways, such as FileInputStream/FileOutputStream or Apache's library, but all of them alter the file structure.
The structure of my file is:
#[Section 1]
prop1=value1
prop2=value2
#[Section 2]
prop2=value2
prop4=value4
After executing the code, the property changes, but "section" items disappear, and file only consists of a list of unordered properties.
Is there a way to preserve the structure above?
I TRIED THESE WAYS: Updating property value in properties file without deleting other values
The general approach for changing any file is to read the contents of the file, keep the content of the file in the memory, change the content that is required and write back the entire content. If you are writing the property values directly then the sections marking would be gone. There is ofcourse one exception in the above case, if you are appending content to the end of the file. Anywhere else, you have to read the file and write the file as a whole.