This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes I/O and Streams and the fly likes Line break for fileOutputStream Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "Line break for fileOutputStream" Watch "Line break for fileOutputStream" New topic

Line break for fileOutputStream

Cathleen Meneses

Joined: Mar 16, 2004
Posts: 21

given the ff code:
FileOutputStream streamOut = new FileOutputStream(new File(strPath),true);
byte [] b = new byte[content.length];
b= content.getBytes();
streamOut.write (b);

how can we insert line breaks after we write array b to the file?
thanks!! ^_^

Joe Ess

Joined: Oct 29, 2001
Posts: 8843

OutputStreams are usually used for binary files. They don't provide any methods to add line breaks so you have to get the line break sequence using System.getProperty("line.separator") and append it to your lines or write it after each line. Error prone and tedious.
A better alternative for working with character based files are the Reader classes. Several of those classes have methods to add new lines. For example, has a newLine() method and has several println() methods.

"blabbing like a narcissistic fool with a superiority complex" ~ N.A.
[How To Ask Questions On JavaRanch]
Cathleen Meneses

Joined: Mar 16, 2004
Posts: 21
thanks Joe! it really helped a lot! now i can move on ^_^ thanks again!
I agree. Here's the link:
subject: Line break for fileOutputStream
Similar Threads
html:file - uploading photo files from jsp into a directory
Hai i need Help in FileOutputStream !
HOw to store image in struts?upload.FormFile
printing new line in file