【发布时间】:2017-12-02 09:19:46
【问题描述】:
我正在创建一个程序以从使用队列的 arrayList 中删除医生。然而,这第一次完美地工作,第二次它复制文本文件中的数据。我该如何解决这个问题?
/**
*
* @throws Exception
*/
public void writeArrayListToFile() throws Exception {
String path = "src/assignment1com327ccab/DoctorRecordsFile.txt";
OutputStreamWriter os = new OutputStreamWriter(new FileOutputStream(path));
BufferedWriter br = new BufferedWriter(os);
PrintWriter out = new PrintWriter(br);
DoctorNode temp; //create a temporary doctorNode object
temp = end; //temp is equal to the end of the queue
//try this while temp is not equal to null (queue is not empty)
StringBuilder doctor = new StringBuilder();
while (temp != null) {
{
doctor.append(temp.toStringFile());
doctor.append("\n");
//temp is equal to temp.getNext doctor to get the next doctor to count
temp = temp.getNext();
}
}
System.out.println("Finished list");
System.out.println("Doctors is : " + doctor.toString());
out.println(doctor.toString());
System.out.println("Done");
br.newLine();
br.close();
}
【问题讨论】:
-
读取文件内容;将其存储在变量中;删除文件;从变量中删除医生;将变量写入新文件;
-
你好 Rafal,我该怎么做?道歉只需要一只手
-
看看我的回答
标签: java filewriter bufferedwriter