以下方法只写出我添加的最新项目,它不会附加到以前的条目。我究竟做错了什么?
public void addNew() {
try {
PrintWriter pw = new PrintWriter(new File("persons.txt"));
int id = Integer.parseInt(jTextField.getText());
String name = jTextField1.getText();
String surname = jTextField2.getText();
Person p = new Person(id,name,surname);
pw.append(p.toString());
pw.append("sdf");
pw.close();
} catch (FileNotFoundException e) {...}
}