File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "Line break for fileOutputStream" Watch "Line break for fileOutputStream" New topic
Author

Line break for fileOutputStream

Cathleen Meneses
Greenhorn

Joined: Mar 16, 2004
Posts: 21
Hi!

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

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

Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8997
    
    9

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, java.io.BufferedWriter has a newLine() method and java.io.PrintWriter has several println() methods.


[How To Ask Questions On JavaRanch]
Cathleen Meneses
Greenhorn

Joined: Mar 16, 2004
Posts: 21
thanks Joe! it really helped a lot! now i can move on ^_^ thanks again!
 
 
subject: Line break for fileOutputStream