The central building block of the Java I/O framework
is the stream:
Stream = One way sequential flow of bytes
Input operations begin by opening a stream
from the source and using a read()
method (there are typically several overridden and overloaded read
methods) to obtain the data via the stream. Similarly, output operations
begin by opening a stream to the destination and using a write()
to send the data (similarly, there are typically several overridden
and overloaded write methods) .
The base stream classes are the abstract classes:
InputStream
- byte input stream base class
OutputStream
- byte output stream base class
Reader
- 16-bit character input stream base class
Writer
- 16-bit character output stream base class
The Reader/Writer
classes were added in Java 1.1 to deal with 16-bit character encoding
(Unicode) of text. Classes
that inherit these abstract classes provide specialized streams
such as for keyboard input, file I/O, etc.
The Java I/O classes either extend or wrap lower level classes
to provide additional capabilities. See the java.io
package specifications for a list of its many stream and ancillary
classes.
With Java 1.4 came new packages, including java.nio
and java.nio.channels,
that add still more I/O related classes. We briefly discuss the
java.nio
(New IO) classes in the Chapter
9: Advanced section.
In fact, a frequent criticism of Java I/O is that it involves too
many classes (see the Class Hierarchy
diagram). Often an entire class, such as PushbackInputStream,
which puts data back into the stream, is required to do a task that
might well have been done by a method within another class.
References & Web
Resources
Latest update: Nov. 10, 2004
|