|Table of Contents
Many Java programs that you write need to read data from some input source or write data to some output source. You have seen several examples in this tutorial of programs that read and write data. For example, the example program featured in The Nuts and Bolts of the Java Language reads data entered by the user and writes data to the display, and the All about Sockets lesson contain several examples that read and write data over the network using sockets.
The Java development environment includes a package, java.io, that contains a set of input and output streams that your programs can use to read and write data. This lesson explains what each class in the java.io packages does, how to decide which one to use, how to use them, and how to write your own. While this lesson does not have an example for every type of input and output stream available in the java.io package, it does provide many practical examples on how to use the most popular classes in java.io.
Your First Encounter with I/O in JavaYou probably first encountered I/O streams in Java through the use of the standard output, standard error, and standard input streams managed by the System class.
Overview of java.io's Input and Output StreamsYour Java programs use input streams to read data from some input source and output streams to write data to some output source. Input and output sources can be anything that can contain data: a file, a string, or memory.
Using Input and Output StreamsThis page shows you the input and output stream pairs that derive directly from InputStream and OutputStream and provides examples for their use.
Working with Filtered StreamsThis page describes what filtered streams are, how to use them, and how to write your own.
Working with Random Access FilesThe java.io.RandomAccessFile implements a random access file that allows you to seek to different locations within the file during reading and writing. This page also provides a special section that shows you how to write filters for objects that implement the DataInput and DataOutput interfaces. Filters implemented in this fashion are more flexible than regular filtered streams because they can be used on random access files and on some sequential files.[PENDING: this lesson does not show examples for File, FileDescriptor, StreamTokenizer, or FilenameFilter. Should it?]
|Table of Contents