In my swing application, I dynamically create components and clicking the save button stores their values to a properties file.
On the value change event of each component, I get the value and put it into a Map. When the save button is clicked, I iterate and store the values to a properties file. Next time I open the window, if the properties file exists, I read the properties from the file and set the values to each component when rendering.
After updating some values again, clicking the save button deletes previous values and the file only contains the changed values.
How can I update the properties file without losing previous values?
Here is my code for writing the properties:
Properties properties = new Properties();
fileOutputStream = new FileOutputStream(propertiesFile);
Iterator itr = attributeMap2.entrySet().iterator();
while (itr.hasNext()) {
Entry<CategoryAttributeObj, String> entry = (Entry<CategoryAttributeObj, String>)itr.next();
properties.setProperty(entry.getKey(), entry.getValue());
}
properties.store(fileOutputStream, "storing index values to properties file");
fileOutputStream.close();
Here is my code for reading the properties:
Properties properties = new Properties();
try {
fileInputStream = new FileInputStream(propertiesFile);
properties.load(fileInputStream);
fileInputStream.close();
}