0

I have a text file that I am writing to. Each time I run the program the old data is erased. I need to be able to save and reopen the file.

The following is a code snippet

import java.io.*;
public class InputFile{
        public static void main(String[] args)throws Exception
        {   

            java.io.File file = new java.io.File("staff.txt");
            java.io.PrintWriter output = new java.io.PrintWriter(file);
.....
......
    System.out.println("Enter staff name \n");
    String staffName = scan.nextLine();
    System.out.println("Enter staff ID \n");
    String staffID = scan.nextLine();
    ....
    ....
    output.printf(staffName + staffID + ", ");
}
....
....

When the user inputs information it should save to text ad can be read later using BufferedReader.

Thanks

DRC

DRC
  • 11
  • 1
  • [Many similar questions and their answers may be easily found](https://www.google.com/webhp?sourceid=chrome-instant&ion=1&espv=2&ie=UTF-8#q=java+append+to+text+file+site:http:%2F%2Fstackoverflow.com%2F) – Hovercraft Full Of Eels May 07 '16 at 14:19
  • If you've still not solved your problem after trying answers found in the above links, then please re-ask your question -- but most importantly, show what you've tried from the links above, and tell how your attempt isn't working. – Hovercraft Full Of Eels May 07 '16 at 14:21

0 Answers0