aspose file tools*
The moose likes Java in General and the fly likes Differece between PrintWriter and OutputStream Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Differece between PrintWriter and OutputStream" Watch "Differece between PrintWriter and OutputStream" New topic
Author

Differece between PrintWriter and OutputStream

Alec Lee
Ranch Hand

Joined: Jan 28, 2004
Posts: 569
If I want to write some arbitrary binary data, can I use PrintWriter instead of OutputStream? I see the PrintWriter does have the write() method although it doesn't have one taking byte/byte[] arguments. If I want to write some binary data, can I just write it using write(int c)?

In short what are the difference between PrintWriter and OutputSteam?
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24184
    
  34

Writer and Reader classes deal with textual characters (type char) and do some translation between Unicode and the real platform's file encoding. Stream classes deal in binary data (type byte), and do no such translation. So the answer is no, if you want to write binary data, don't use any Writer class; use an OutputStream of some kind.

Here is a nice tutorial which teaches you all about these classes, their relationships, and their uses.


[Jess in Action][AskingGoodQuestions]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Differece between PrintWriter and OutputStream