private static void displaytoFile(int trial, int count) {
// TODO Auto-generated method stub
String answer;
try{
// Create file
FileWriter fstream = new FileWriter(outputfile);
BufferedWriter out = new BufferedWriter(fstream);
answer = "Case #"+trial+": "+count;
out.write(answer);
out.newLine();
//Close the output stream
out.close();
}catch (Exception e){//Catch exception if any
System.err.println("Error: " + e.getMessage());
}
}
The displaytoFile() method is called in a loop in my project but i am not able to write line by line into the file.It only writes the last line ie the parameters passed during the last iteration.I tested in console and the other code is ok,it displays all but this code snippet seems to have some problem as it seems it overwrites the previous values.How can i get to write to file line by line?