Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Writing an Empty Line in a File....

 
Somnath Mallick
Ranch Hand
Posts: 483
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Everyone,

I want to write an empty line in a file. I am trying to save a String variable with the value newLine = "\n". And then trying to write it to the file using the method fileOutputStream.write(newLine.getBytes()). But the thing is i only get a black empty square rather than an empty line.
 
Ryan Beckett
Ranch Hand
Posts: 192
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Use an IO Wrapper : PrintWriter.println() or BufferedWriter.newLine() and don't forget to close the streams if you do.
 
Somnath Mallick
Ranch Hand
Posts: 483
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I created an object of the PrintWriter class passing the file through the constructor.

PrintWriter printWriter = new PrintWriter(outputFile);

And then when i try to write anything to the file nothing turned up.
printWriter.write(NameRemovalConstants.commentLine1); added nothing to the file.
even
PrintWriter printWriter = new PrintWriter(new FileOutputStream(outputFile,false))

Even this didn't help.


 
Somnath Mallick
Ranch Hand
Posts: 483
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have modified the code after a little googling and now i have changed the print writer object to
PrintWriter printWriter = new PrintWriter(new FileWriter(outputFile));

But when i am writing to the file i keep getting the empty blank squares.
printWriter.println(ServiceRemovalConstants.commentLine1);
Only this time not at the end of the line but at the beginning.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic