Java Reference
In-Depth Information
20.5. A Quick Tour of the Stream Classes
The
java.io
package defines several types of streams. The stream types
usually have input/output pairs, and most have both byte stream and
character stream variants. Some of these streams define general beha-
vioral properties. For example:
•
Filter
streams are abstract classes representing streams with
some filtering operation applied as data is read or written by an-
other stream. For example, a
FilterReader
object gets input from
another
Reader
object, processes (filters) the characters in some
manner, and returns the filtered result. You build sequences of
filtered streams by chaining various filters into one large filter.
Output can be filtered similarly (
Section 20.5.2
).
•
Buffered
streams add buffering so that
read
and
write
need not, for
example, access the file system for every invocation. The charac-
ter variants of these streams also add the notion of line-oriented
text (
Section 20.5.3
).
•
Piped
streams are pairs such that, say, characters written to a
PipedWriter
can be read from a
PipedReader
(
Section 20.5.4
).
A group of streams, called
in-memory streams,
allow you to use in-
memory data structures as the source or destination for a stream:
•
ByteArray
streams use a
byte
array (
Section 20.5.5
).
•
CharArray
streams use a
char
array (
Section 20.5.6
).
•
String
streams use string types (
Section 20.5.7
).
The I/O package also has input and output streams that have no output
or input counterpart:
•
The
Print
streams provide
print
and
println
methods for format-
ting printed data in human-readable text form (
Section 20.5.8
).