I'm creating a game that needs to keep track of the highscores as different people play it. I'd like it to be able to organize itself, so that the top player stays at the top, and the file isn't always overwritten when a new score is added. I need at least 6 scores saved at once.
Here is my highscore writing method:
public void high_score() throws IOException {
Writer output = null;
String text = "Highscore:" + replay_score;
File file = new File("C:\\Users\\Liam\\Desktop\\BOMB GAME\\Bomb_Highscores.txt");
output = new BufferedWriter(new FileWriter(file));
output.write(text);
output.close();
System.out.println("Your file has been written");
}
Where replay_score
is the number of times you've replayed the game until you've scored high enough to beat it.