Pages

Tuesday, May 10, 2011

Working with Filtered Streams

You attach a filtered stream to another stream to filter the data as it's read from or written to the original stream. The java.io package contains these filtered streams which are subclasses of either FilterInputStream or FilterOutputStream:

DataInputStream and DataOutputStream

BufferedInputStream and BufferedOutputStream

LineNumberInputStream

PushbackInputStream

PrintStream (this is an output stream)

This section shows you how to use filtered streams through an example that uses a DataInputStream and a DataOutputStream. In addition, this section shows you how to write your own filtered streams.

Using Filtered Streams

To use a filtered input or output stream, attach the filtered stream to another input or output stream. For example, you can attach a DataInputStream to the standard input stream as in the following code:

Disclaimer

Java Jazzle is for learning and training only. Its not guaranteed that content published is correct. The risk from using it lies entirely with the user. Also the opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.

About this blog

This is my tech blog. I write on this blog to save my searching stuff on google. It acts as my log of all the stuff I went through and saves my time, because I don't have to search again and again. Another reason for putting stuff on it was, when I am kind of free, it kind of kills it.