I want my program to check if there is data in the text file and add more data below it.
I can write to the file but I don't know how to check if there is already data in the file and how to add more information below it. It currently just overrides the existing information.
try (
FileWriter file = new FileWriter("name.txt");
PrintWriter out = new PrintWriter(file);
Scanner sc = new Scanner(System.in);
) {
out.println("Name:" + firstname + " " + middlename + " " + lastname);
out.println("DOB:" + birthday);
out.println("Phone:" + phone);
out.println("Address:" + address);
} catch(IOException e) {
System.out.println("Error!");
}
It should add more information below the existing information, not replace it.
For example: Name: anon anon anon DOB:010200 Phone:12345678 Address: anon
Then when I run the code again I want it the write the new information below it.