-1

So everytime someone clicks sign up on my program, I call a method that opens file and adds record.
This is to open the file:

try {
    l = new Formatter("chineses.txt");
    System.out.println("Did create");
} catch (Exception e){
    System.out.println("Did not create");
}

public void addRecord(){ //This is how i add the record
    l.format("%s", nameField.getText());
}

Everytime I put in a name in the name field and click sign up in my gui, it always replaces whatever is on the first line in the text file.
How can I make it go to the second line while retaining what is on the first line each time someone else puts their name and clicks sign up?

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
adoba yua
  • 41
  • 7

1 Answers1

2

You just need to create the object of FileWriter and pass it to the Formatter. It will append your text in the File.

Try this code:

FileWriter writer = new FileWriter("chineses.txt",true);
l = new Formatter(writer);

public void addRecord(){ //This is how i add the record
    l.format("%s\n", nameField.getText());
}
Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62