This week's giveaway is in the Spring forum.
We're giving away four copies of REST with Spring (video course) and have Eugen Paraschiv on-line!
See this thread for details.
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

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Differece between PrintWriter and OutputStream" Watch "Differece between PrintWriter and OutputStream" New topic

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

Joined: Jul 08, 2003
Posts: 24195

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]
subject: Differece between PrintWriter and OutputStream
It's not a secret anymore!