• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

New Line in Java?

 
Andy Boyd
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello all,
I am new to java and have a question about file output. I am using the filewriter to access a basic text document. I am writing out short strings and would like each one on a new line but they are just being concatenated into one large string. I would like to be able to get my output to go on to a new line each time I write to the file. Any help? Thanks
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24208
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Welcome to JavaRanch!
Perhaps the easiest thing to do looks like this:
 
Sadanand Murthy
Ranch Hand
Posts: 382
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Look at the documentation for PrintWriter.
It has a method called print() which will print and stay at that line. So the next call to print() or println() will print on the same line.
Another method called println() will print and terminate that line. So the next call to print() or println() will automatically print on a new line.
 
Andy Boyd
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot. The Print Writer method worked great.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic