0

I currently have.

public void openFile(){
    try{
        x = new Formatter("Data.text");
    }
    catch(Exception e){
        System.out.println("File not created");
    }
}

. . . .

.

.

public void addRecords(){
    x.format("%s %s %s %s", first(), last(), ID(), num());
}

But after I run the file, it overwrites the data each time?

  • This is similar to or a duplicate of http://stackoverflow.com/questions/1625234/how-to-append-text-to-an-existing-file-in-java – Mohammad Najar Oct 13 '14 at 18:24

1 Answers1

0

Formatter will truncate the size of the file to 0. Use PrintWriter instead. Then you can use the PrintWriter's printf to do the same thing.

dramzy
  • 1,379
  • 1
  • 11
  • 25