Java Reference
In-Depth Information
20.1. Streams Overview
The package java.io has two major parts: character streams and byte
streams. Characters are 16-bit UTF -16 characters, whereas bytes are (as
always) 8 bits. I/O is either text-based or data-based (binary). Text-
based I/O works with streams of human-readable characters, such as the
source code for a program. Data-based I/O works with streams of binary
data, such as the bit pattern for an image. The character streams are
used for text-based I/O, while byte streams are used for data-based I/O.
Streams that work with bytes cannot properly carry characters, and some
character-related issues are not meaningful with byte streamsthough the
byte streams can also be used for older text-based protocols that use 7-
or 8-bit characters. The byte streams are called input streams and out-
put streams, and the character streams are called readers and writers.
For nearly every input stream there is a corresponding output stream,
and for most input or output streams there is a corresponding reader or
writer character stream of similar functionality, and vice versa.
Because of these overlaps, this chapter describes the streams in fairly
general terms. When we talk simply about streams, we mean any of
the streams. When we talk about input streams or output streams, we
mean the byte variety. The character streams are referred to as read-
ers and writers. For example, when we talk about the Buffered streams
we mean the entire family of BufferedInputStream , BufferedOutputStream ,
BufferedReader , and BufferedWriter . When we talk about Buffered byte
streams we mean both BufferedInputStream and BufferedOutputStream .
When we talk about Buffered character streams, we mean BufferedReader
and BufferedWriter .
The classes and interfaces in java.io can be broadly split into five groups:
The general classes for building different types of byte and char-
acter streamsinput and output streams, readers and writers, and
classes for converting between themare covered in Section 20.2
through to Section 20.4 .
 
Search WWH ::




Custom Search