Java Reference
In-Depth Information
Byte Streams and Character Streams
Modern versions of Java define two types of I/O streams: byte and character. (The original
version of Java defined only the byte stream, but character streams were quickly added.)
Byte streams provide a convenient means for handling input and output of bytes. They are
used, for example, when reading or writing binary data. They are especially helpful when
working with files. Character streams are designed for handling the input and output of
characters. They use Unicode and, therefore, can be internationalized. Also, in some cases,
character streams are more efficient than byte streams.
The fact that Java defines two different types of streams makes the I/O system quite large
because two separate sets of class hierarchies (one for bytes, one for characters) are needed.
The sheer number of I/O classes can make the I/O system appear more intimidating than it
actually is. Just remember, for the most part, the functionality of byte streams is paralleled
by that of the character streams.
One other point: At the lowest level, all I/O is still byte-oriented. The character-based
streams simply provide a convenient and efficient means for handling characters.
The Byte Stream Classes
Byte streams are defined by using two class hierarchies. At the top of these are two
abstract classes: InputStream and OutputStream . InputStream defines the characterist-
ics common to byte input streams and OutputStream describes the behavior of byte output
streams.
From InputStream and OutputStream are created several concrete subclasses that of-
fer varying functionality and handle the details of reading and writing to various devices,
such as disk files. The byte stream classes are shown in Table 10-1 . Don't be overwhelmed
by the number of different classes. Once you can use one byte stream, the others are easy
to master.
Search WWH ::




Custom Search