wood burning stoves 2.0*
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


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "PrintWriter" Watch "PrintWriter" New topic
Author

PrintWriter

Jon Camilleri
Ranch Hand

Joined: Apr 25, 2008
Posts: 660

"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?


Jon
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14272
    
  21

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
 
wood burning stoves
 
subject: PrintWriter