It's not a secret anymore!
The moose likes Beginning Java and the fly likes PrintWriter Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "PrintWriter" Watch "PrintWriter" New topic


Jon Camilleri
Ranch Hand

Joined: Apr 25, 2008
Posts: 664

"Prints formatted representations of objects to a text-output stream. This class implements all of the print methods found in PrintStream. It does not contain methods for writing raw bytes, for which a program should use unencoded byte streams."

Sourced from here.

Can you clarify the latter sentence, preferably with an example, please?

Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 15082

In Java I/O, there are two kinds of classes: streams, which are meant for reading and writing bytes directly from and to a file, network connection or other communication medium, and readers and writers, which are meant for reading and writing text.

Readers and writers are something that builds on streams: they use streams below the covers to read and write data, and what they add is interpreting the raw bytes as characters, using a character encoding.

A PrintWriter is obviously a writer, meant for writing text; it does not provide a way to directly write raw bytes (without using a character encoding).

Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
I agree. Here's the link:
subject: PrintWriter
It's not a secret anymore!