'Properties file resets when adding or updating value (Java)
I'm storing user data (nothing important, just user ID and xp amount/level) in a properties file. When using prop.store(output, comment) it resets the file completely and then stores the added data. How can I add data without it resetting the entire file?
Solution 1:[1]
Each time you use the store() method, it removes the old data and writes the new data.
To prevent this from happening, you must first load your data and then restore it with new data that you want to add.
This code snippet may help you:
Properties prop = new Properties();
prop.load(new FileInputStream(YOUR_PROPERTIE_FILE));
prop.setProperty(key, value);
prop.store(new FileOutputStream(YOUR_PROPERTIE_FILE), COMMENT);
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Soroush Shemshadi |
