0

My program writes entries of text to a file. Each entry is 4 word tokens written on a line. I want each entry to go on its own line, but the output I'm getting so far is:

abc1 abc1 abc1 abc1 abc2 abc2 abc2 abc2 abc3 abc3 abc3 abc3

(i.e. everything on the same line)

Here's my code:

//targetFile = "C://...."
BufferedWriter writer = new BufferedWriter(new FileWriter("targetFile, true));
String s;
s = userInfo1;     //userInfo is an array of 4 word tokens
writer.append(s + " ");
writer.flush();
Dennis Meng
  • 5,109
  • 14
  • 33
  • 36
noBrainer
  • 29
  • 1
  • 5
  • Exact duplicate of [Strings written to file using BufferedWriter](http://stackoverflow.com/questions/9199216/strings-written-to-file-using-bufferedwriter). – jww Oct 12 '14 at 05:04

2 Answers2

2

Try this

writer.write(s);
writer.newLine();

or use PrintWriter instead of BufferedWriter:

printWriter.println(s);
Evgeniy Dorofeev
  • 133,369
  • 30
  • 199
  • 275
-2

Try writer.append(s + "\r\n");

MEAN Developer
  • 277
  • 2
  • 10