Filter Streams

The and classes are concrete subclasses of InputStream and OutputStream that somehow modify data read from an underlying stream. You rarely use these classes directly, but their subclasses are extremely important, especially DataInputStream and DataOutputStream.

You connect filter streams to an underlying stream that supplies the actual bytes of data by passing the original stream to the filter stream's constructor. For example, to create a new DataOutputStream from a FileOutputStream you might do this:

FileOutputStream fos = new FileOutputStream("ln.txt");
DataOutputStream dos = new DataOutputStream(fos);

It's not uncommon to combine these into one line like this:

DataOutputStream dos = new DataOutputStream(new FileOutputStream("ln.txt"));

Previous | Next | Top | Cafe au Lait

Copyright 1997-1999 Elliotte Rusty Harold
Last Modified November 19, 1999