PrintWriter append 方法不追加
2022-08-31 16:48:11
以下方法仅写出我添加的最新项目,它不会追加到以前的条目。我做错了什么?
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) {...}
}