I'm trying to append an array of strings onto my text file but I also want to rewrite the first line each time too.
This is how I save my text (I attempted to append):
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");
}