Search code examples
javaoutputprintwriterdata-entry

How to make printwriter output to .txt remember multiple data entries


I am making a simple program to input some data (Name, A Game, an Achievement Score and Minutes played) and whenever I input one piece of data (max of 100) it only remembers the last one inputted

https://i.gyazo.com/d4a51acc564fb459b9e590c7474700d8.png

I wanted it to remember all entries in a list

        try
        {
            PrintWriter writer = new PrintWriter("Gamer Report Data.txt");
            writer.println("Player : " + gamerName);
            writer.println();
            writer.println("--------------------------------");
            writer.println();
            String[] report = gamerReport.split(":");
            writer.println("Game: " + report[0] + ", score= " +report[1] + ", minutes played= " +report[2]);
            writer.close();
        } catch (IOException e)
        {
            System.err.println("File does not exist!");
        }

        }



    }

    public static char[] getInput() {
        return input;
    }

    public static void setInput(char[] input) {
        JavaProject.input = input;
    }

}

Solution

  • You need to open your PrintWriter using a FileOutputStream with append set to true