I cant write string in file in new line, although i add “\n” to the end of string
public void writeEquation(String fileName, String expr) {
File aFile = new File(fileName);
try {
FileWriter writer = new FileWriter(aFile, true);
BufferedWriter buffered = new BufferedWriter(writer);
buffered.write(expr+"\n");
buffered.flush();
buffered.close();
} catch (IOException e1) {
e1.printStackTrace();
}
}
where is the mistake?
Why not use the newLine() method provided by the
BufferedWriterclass?In your code, change:
to :
Later edit: Also I am not sure where you want the new line, but if you want to make sure that your
exprstring gets added on a new line at the end of a file, then call the method before callingbuffered.write(expr)like: