我在用 Java 写入文件时遇到问题。我想写入 .txt 文件,但是当程序写入任何内容时,它会在写入之前删除。我不想要它。我在使用 flw.append 之前使用了 flw.write,但没有任何改变。你能帮助我吗 ?
public void list(String path) throws IOException {
FileWriter flw=new FileWriter(path);
flw.append("----------------------------------------------List---------------------------------------------\n");
for (int i = 0; i < athCtr - 1; i++) {
flw.append("Author:" + athr[i].getId() + "\t"
+ athr[i].getName() + "\t" + athr[i].getUniv() + "\t"
+ athr[i].getDepart() + "\t" + athr[i].getEmail()+"\n");
if (athr[i].getArtCtr() != 0) {
for (int j = 0; j < athr[i].getArtCtr(); j++) {
flw.append("+" + athr[i].getArticle(j) + ":");
for (int k = 0; k < artCtr; k++) {
if (art[k].getPaperId().equals(athr[i].getArticle(j))) {
flw.append("\t" + art[k].getName() + "\t"
+ art[k].getPublisherName() + "\t"
+ art[k].getPublishYear()+"\n");
}
}
}
flw.append("\n");
}
}
flw.append("Author:" + athr[athCtr - 1].getId() + "\t"
+ athr[athCtr - 1].getName() + "\t"
+ athr[athCtr - 1].getUniv() + "\t"
+ athr[athCtr - 1].getDepart() + "\t"
+ athr[athCtr - 1].getEmail()+"\n");
if (athr[athCtr - 1].getArtCtr() != 0) {
for (int j = 0; j < athr[athCtr - 1].getArtCtr(); j++) {
flw.append("+" + athr[athCtr - 1].getArticle(j) + ":");
for (int k = 0; k < artCtr; k++) {
if (art[k].getPaperId().equals(
athr[athCtr - 1].getArticle(j))) {
flw.append("\t" + art[k].getName() + "\t"
+ art[k].getPublisherName() + "\t"
+ art[k].getPublishYear()+"\n");
}
}
}
}
flw.append("----------------------------------------------End----------------------------------------------\n\n");
flw.close();
}