appending to new line in text file
807597Oct 31 2005 — edited Aug 29 2009I am trying to append text to a new line to a file. I set the append parameter to true and I try to output the new line character after I write the string to the file. However it is still appending the next string to the end of the first rather than in the line below. My code is below. Can someone please help me?
Thanks
public static boolean WriteToFile(String nameOfFile,
String contents)
{
FileWriter myFileWriter = null;
try
{
System.out.println("Attempting to write text to = " + nameOfFile);
myFileWriter = new FileWriter(nameOfFile,true);
myFileWriter.write(contents);
myFileWriter.write('\n');
myFileWriter.close();
return true;
}
catch (Exception e)
{
System.out.println("EXCEPTION thrown ");
return false;
}
}