Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

PrintWriter

 
Jon Camilleri
Ranch Hand
Posts: 664
Chrome Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"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
Posts: 15272
37
Android IntelliJ IDE Java Scala Spring
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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).
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic