I'm trying to keep track of a high score in a game I'm making by doing:
PrintWriter out = new PrintWriter(new File("path"));
while(gameLoop) {
out.write(highScore);
out.flush();
}
It keeps appending the data to the end of the file. I am aware I could out.close();
and then out = new PrintWriter(new File("path"));
but that seems like a lot of excess code. Constantly closing and re-opening the file to achieve overwrite. Is there any way for my PrintWriter
to overwrite the data without closing and re-opening the file?