In my web application I succeed in displaying data in html table using mybatis. Now I want to save the records of the Mysql table in a json file and create an array of users, I
You write all the users in same file C:\\file.json
so just the last iteration of the loop saved.
You can convert the object List
into json and write it once (no needed loop)
Example:
try (Writer writer = new FileWriter("Output.json")) {
Gson gson = new GsonBuilder().create();
gson.toJson(users, writer);
}