public void load() throws IOException { File file = getFile(); if (file.exists()) { JsonObject rootObject = JSON_PARSER.parse(new FileReader(file)).getAsJsonObject(); for (JsonElement element : rootObject.getAsJsonArray("players")) { Player player = new Player(element.getAsJsonObject()); playerDB.put(player.getName(), player); } for (JsonElement element : rootObject.getAsJsonArray("groups")) { Group group = new Group(element.getAsJsonObject()); groupDB.put(group.getName(), group); } } else { //noinspection ResultOfMethodCallIgnored file.createNewFile(); JsonObject rootObject = new JsonObject(); rootObject.add("players", new JsonArray()); rootObject.add("groups", new JsonArray()); BufferedWriter bw = new BufferedWriter(new FileWriter(file)); bw.write(GSON.toJson(rootObject)); bw.close(); } }