I want to write results to the end of the file using java
FileWriter fStream;
try {
fStream = new FileWriter("recallPresision.txt", true);
fStream.append("queryID=" + queryID + " " + "recall=" + recall + " Pres=" + presision);
fStream.append("\n");
fStream.flush();
fStream.close();
} catch (IOException ex) {
Logger.getLogger(query.class.getName()).log(Level.SEVERE, null, ex);
}
I put I want to print results with new line "\n"
in the statement , it writes to the file but not with new line
The newline sequence is system dependent. On some systems its \n
, on others it's \n\r
, \r\n
, \r
or something else entirely different. Luckily, Java has a built in property which allows you to access it:
String newline = System.getProperty("line.separator");
fStream.append("\n");
// don't guess the line separator!
fStream.append(System.getProperty("line.separator"));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With