Previous | Next | Trail Map | The Java Development Environment | Package Tour


The Java I/O Package

The Java I/O package, a.k.a. java.io, provides a set of input streams and a set of output streams used to read and write data to files or other input and output sources. There are three categories of classes in java.io: input streams, output streams and everything else.

The pages of this lesson provide overviews of Java's I/O classes. They give information about what each class does and how you can use them. These pages do not provide any practical examples or details of each class. For more practical information regarding reading and writing data using these classes, see Input and Output Streams .

Input Streams

Input streams read data from an input source. An input source can be a file, a string, or memory--anything that can contain data. All input streams inherit from InputStream--an abstract class that defines the programming interface for all input streams.

The InputStream class defines a programming interface for reading bytes or arrays of bytes, marking locations in the stream, skipping bytes of input, finding out the number of bytes that are available for reading, and resetting the current position within the stream. An input stream is automatically opened when you create it. You can explicitly close a stream with the close() method, or let it be closed implicitly when the object is garbage collected.

Output Streams

Output streams write data to an output source. Similar to input sources, an output source can be anything that can contain data: a file, a string, or memory.

The OutputStream class is a sibling to InputStream and is used to write data that can then be read by an input stream. The OutputStream class defines a programming interface for writing bytes or arrays of bytes to the stream and flushiing the stream. Like an input stream, an output stream is automatically opened when you create it. You can explicitly close an output stream with the close() method, or let it be closed implicitly when the object is garbage collected.

Everything Else

In addition to the streams classes, java.io contains a few other classes:
File
Represents a file on the host system.
RandomAccessFile
Represents a random access file.
StreamTokenizer
Tokenizes the contents of a stream.

See Also

java.io


Previous | Next | Trail Map | The Java Development Environment | Package Tour