我试图在我的文本文件中附加一个字符串数组,但我也想每次都重写第一行。
这是我保存文字的方式(我试图追加):
public static void saveText (String[] studentArray, String assignArray [], String fileName, int numStudents) throws IOException {
File dumpFile = new File(fileName + ".txt");
if (!dumpFile.exists()) {
dumpFile.createNewFile();
}
FileWriter fw = new FileWriter (dumpFile, true);
BufferedWriter bw = new BufferedWriter (fw);
bw.write(Integer.toString((int)numStudents));
bw.newLine();
for (int i = 0; i < studentArray.length; i++) {
bw.write(studentArray[i]);
bw.write(", ");
}
for (int i = 0; i < assignArray.length; i++) {
bw.write(assignArray[i]);
bw.write(", ");
}
bw.close();
System.out.println("SUCCESFULLY DUMPED FILE");
}