aspose file tools*
The moose likes I/O and Streams and the fly likes Writing an Empty Line in a File.... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "Writing an Empty Line in a File...." Watch "Writing an Empty Line in a File...." New topic
Author

Writing an Empty Line in a File....

Somnath Mallick
Ranch Hand

Joined: Mar 04, 2009
Posts: 477
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

Joined: Feb 22, 2009
Posts: 192
Use an IO Wrapper : PrintWriter.println() or BufferedWriter.newLine() and don't forget to close the streams if you do.
Somnath Mallick
Ranch Hand

Joined: Mar 04, 2009
Posts: 477
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

Joined: Mar 04, 2009
Posts: 477
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.
 
 
subject: Writing an Empty Line in a File....