I need the code to write without destroying the current data in the file.
I want to store my scores in the file, after every game the score needs to be scored in the Highscore file.
My current problem is that after every game the file rewrites, I don't want that.
public void read() { File file = new File("C:/Users/nnnvi/Documents/Greenfoot copy/CricketGame-copy/Highscore.txt"); try { lines = Files.readAllLines(file.toPath()); } catch(IOException e) { System.err.println("An exception occurred"); } theLines = lines.toArray(new String[0]); } public void write() { try { String text = Integer.toString(myScore); Path fileName = Path.of("C:/Users/nnnvi/Documents/Greenfoot copy/CricketGame-copy/Highscore.txt"); Files.writeString(fileName, text); }catch(IOException e) { System.err.println("An exception occurred"); } }