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


Output Streams

The following diagram shows the class hierarchy for the output stream classes provided by the java.io package. OutputStream inherits from the Object class; four classes inherit directly from OutputStream; FilterOutputStream is an abstract class with three direct descendents.
Note: you can click on any of the class symbols in the following image to visit the API documentation for that class.

Each of the OutputStreams provided by the java.io package is intended for a different purpose, either writing to a different type of output source or writing a specific type or form of data.

Simple Output Streams

To write to a file: use FileOutputStream.
To write to a pipe: use PipedOutputStream. Typically attached to a PipedInputStream.
To write to a buffer: use ByteArrayOutput.

Filter Output Streams

FilterOutputStream is an abstract class that defines the interface for filtered output streams. Filtered output streams have some intelligence built into them about the data that they are writing. You are no doubt already familiar with one of the descendents of FilterOutputStream: the PrintStream class. System.out and System.err are both instances of PrintStream. PrintStream provides extra methods for conveniently printing Strings and other data.

How to Use the Filtered Streams

To write primitive Java data types: use DataOutputStream.
For an efficient stream that buffers while writing: use BufferedOutputStream.
For a stream with convenient printing methods: use PrintStream.


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