Hey so I'm trying to write json files and I can't seem a source anywhere explaining why the whole file gets overridden and gets back to square one, this is the code I happen to be using.
JSONObject j = new JSONObject();
j.put("name", member.getUser().getName());
JSONObject group = new JSONObject();
group.put(String.valueOf(Math.random()), j);
String fileName = "test.json";
try (FileWriter file = new FileWriter(fileName)) {
file.write(group.toString());
file.flush();
} catch (IOException e) {
e.fillInStackTrace();
}
My JSON file gets written like this,
{"0.027601526266715193":{"name":"Keurig"}}
But if I run it again it does not add another group how I want it to it just overrides the file, this is how I wanted it to be.
{"0.027601526266715193":{"name":"Keurig"}, "0.02015264243212141":{"name":"Keurig"}}