This module gave you a tour of classes you can use to perform input/output in Java.
Classes in the I/O package fall into two broad categories: InputStreams and OutputStreams.
Subclasses of these two abstract classes implement the details of their read() and write() methods.
One particularly useful set of classes is DataInputStream and DataOutputStream. With instances of these classes, you can read and write specific Java data types, such as int,
rather than reading and writing generic bytes.
There is also a File class that represents a node on the file system. Instances of this class can be either a file or directory.
An I/O Stream represents an input source or an output destination. A stream can represent many different kinds of sources and destinations, including disk files, devices, and memory arrays.
Streams support many different kinds of data, including simple bytes, primitive data types, localized characters, and objects. Some streams simply pass on data while others manipulate and transform the data in useful ways.
No matter how they work internally, all streams present the same simple model to programs that use them.
A stream is a sequence of data and a program uses an input stream to read data from a source, one item at a time. To gain a better understanding of how this works, take a look at the 2 images displayed below.
Reading Information into Program
Writing Information from a program
A program uses an output stream to write data to a destination, one item at time:
The data source and data destination pictured above can be anything that holds, generates, or consumes data.
Obviously this includes disk files, but a source or destination can also be another program, a peripheral device, a network socket, or an array.