Java Reference
In-Depth Information
Low-Level Readers and Writers
A reader is used for performing character I/O, and the java.io.Reader class is
the parent class of all readers. Similarly, the java.io.Writer class is the parent
class of all writers. Readers and writers, similarly to streams, can be broken
down into two categories: low level and high level. The low-level readers and
writers connect directly to a data source, similarly to memory or a file, while
the high-level readers and writers connect to existing readers and writers.
The low-level readers in the java.io package are:
CharArrayReader and CharArrayWriter.
For reading from and writing
to arrays of characters.
FileReader and FileWriter.
For reading from and writing to files contain-
ing character data.
PipedReader and PipedWriter. For creating character streams between
two threads. An example of pipes is discussed in the upcoming Using
Pipes section.
StringReader and StringWriter.
For reading from and writing to String
objects.
The upcoming section, File I/O , demonstrates using the FileWriter class.
Using the other low-level readers and writers is similar.
High-Level Readers and Writers
The high-level readers and writers in the java.io package are:
BufferedReader and BufferedWriter. For buffering the characters in the
character stream. Using these classes is similar to using the BufferedIn-
putStream and BufferedOutputStream classes.
InputStreamReader and OutputStreamWriter. For converting between
byte streams and character streams. The sidebar Reading Input from the
Keyboard in this chapter demonstrates converting a stream to a reader.
PrintWriter. For printing text to either an output stream or a Writer. You
have seen a PrintWriter used extensively: System.out is a PrintWriter
object.
PushbackReader. For readers that allow characters to be read and then
pushed back into the stream.
Now that we have seen how the classes in the java.io package break down
into streams, readers and writers, and low-level and high-level streams, let's
Search WWH ::




Custom Search