This code will add text to new line but is there a way to write to the last line of the file?
try (FileWriter fileWriter = new FileWriter(file)) {
fileWriter.append("{\"receivedtime\":\""+dateReceived+"\", " + "\"text\":\""+text+"\"}");
fileWriter.flush();
}
As you can see I am writing JSON file with java. But there is this comma issue at the end of the line if there is another line. So I thought if I had a new line I will add the comma then the \n then the line. For the last line I don't need the comma so just the end ]}
{"employees":[
{"firstName":"Anna", "lastName":"Smith"},
{"firstName":"Peter", "lastName":"Jones"}
]}