My code for writing to a text file now looks like this:
public void resultsToFile(String name){
try{
File file = new File(name + ".txt");
if(!file.exists()){
file.createNewFile();
}
FileWriter fw = new FileWriter(file.getAbsoluteFile());
BufferedWriter bw = new BufferedWriter(fw);
bw.write("Titel: " + name + "\n\n");
for(int i = 0; i < nProcess; i++){
bw.write("Proces " + (i) + ":\n");
bw.write("cycles needed for completion\t: \t" + proc_cycle_instr[i][0] + "\n");
bw.write("instructions completed\t\t: \t" + proc_cycle_instr[i][1] + "\n");
bw.write("CPI: \t" + (proc_cycle_instr[i][0]/proc_cycle_instr[i][1]) + "\n");
}
bw.write("\n\ntotal Cycles: "+totalCycles);
bw.close();
}catch(IOException e){
e.printStackTrace();
}
}
However, This overwrites my previous text files, whilst instead I want it to be appended to the already existing file! What am I doing wrong?