The java.io.FilterInputStream
and java.io.FilterOutputStream
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"));