I'm looking for a way to be able to read a file and rewrite the same file but taking into account all the information inside it to order it from highest to lowest
/*Scores*/
Mathew: 540
Stacy: 070
Andre: 761
Alfred: 340
So that would be how it's written in my .txt file and I want it to be:
/*Scores*/
Andre: 761
Mathew: 540
Alfred: 340
Stacy: 070
I'm writing the file for each level, the following way:
public void scoreWrite(int levelID) throws IOException {
File Highscores = new File("Scoreboard/Level_" + levelID + "_Highscore.txt");
// Level_0_Highscore.txt
if(Highscores.createNewFile()) {
FileWriter highscoreWriter = new FileWriter(Highscores, false);
highscoreWriter.write("/*---Highscores---*/ \n \n");
highscoreWriter.write(SokobanGame.getInstance().getPlayerName()+ "'s " + "score: " + getScore() + " points;\n");
highscoreWriter.close();
}else {
Highscores = new File("Scoreboard/Level_" + levelID + "_Highscore.txt");
FileWriter highscoreWriter = new FileWriter(Highscores, true);
highscoreWriter.write(SokobanGame.getInstance().getPlayerName()+ "'s " + "score: " + getScore() + " points;\n");
highscoreWriter.close();
}
}
But now for the way to order, I'm at a complete loss... Any help would be appreciated!