Java Reference
In-Depth Information
Chapter 9
Java input/output
9.1 Introduction
Java provides a consistent framework for all input/output. That framework centers
on the concept of a stream .Astream in Java is a sequential flow of bytes in
one direction. There is an output stream that carries text to the console and a
corresponding input stream that brings text from the keyboard. Another type of
output stream carries data to a file, and a corresponding input stream brings data
into a program from a file. There is another output stream that sends data through
a network port to another computer on the network while an input stream brings
in data through a network port from such a source.
The bulk of Java I/O classes belong to the java.io package. (See diagram
in Figure 9.1.) The class hierarchy builds on the base classes InputStream ,
OutputStream , Reader , and Writer to provide a wide range of input and
output tasks. In addition, this package holds stream classes that wrap a stream to
add more capabilities to it. Some I/O classes provide a destination or source, such
as a file or an array. Others process the stream in some way such as buffering or
filtering the data.
Packages involving I/O include:
java.io - the primary Java I/O classes
java.nio , java.nio.* -aset of five packages new with Java 1.4 based on the
concept of channels that represent an open connection to a hardware device, file, or
other entity. Channels don't supplant streams but rather work with them to add additional
capabilities and enhanced scaling when working with large numbers of connections
java.net - I/O over the network
java.util.zip - methods for reading from and writing to ZIP and GZIP files
java.util.jar - methods for reading from and writing to JAR (Java Archive) files
javax.imageio , javax.imageio.* - this set of six packages deals with image
I/O, including the encoding/decoding of images in particular formats (discussed in
Chapter 11)
Java I/O is an enormous topic that involves many packages, classes, and methods
[1,2]. Here we give an overview of some of the basic aspects of Java I/O with
287
Search WWH ::




Custom Search