In Java 1.0, data flow adapts to specific requirements through FilterInputStream and Filteroutputstream's "adorner" (decorator) subclasses. The Java 1.1 io stream follows this idea, but does not continue to use all adorners derived from the same "filter" base class. This can be a little confusing if you understand it by looking at the hierarchy of classes.
In the following table, the corresponding relationship is more rough than the previous one. This difference is caused by the organization of the class: Although Bufferedoutputstream is a subclass of Filteroutputstream, BufferedWriter is not a subclass of Filterwriter (for the latter, Although it is an abstract class, but does not have its own subclasses or approximate subclasses of things, nor a "placeholder" available, so do not bother to look for. However, the interfaces of the two classes are very similar, and in any case, it is obvious that the new version should be used as much as possible, rather than the old version (that is, unless a stream must be generated in some classes, no reader or writer can be generated).
Filters: Java 1.0 Class
|
Corresponding Java 1.1 class
|
FilterInputStream
|
FilterReader
|
Filteroutputstream
|
Filterwriter (abstract class with no subclasses)
|
Bufferedinputstream
|
BufferedReader (also has readLine ())
|
Bufferedoutputstream
|
BufferedWriter
|
DataInputStream
|
Use datainputstream (Except When you need the use of readLine (), when your should use a bufferedreader)
|
PrintStream
|
PrintWriter
|
Linenumberinputstream
|
LineNumberReader
|
Streamtokenizer
|
Streamtokenizer (use constructor that takes a Reader instead)
|
Pushbackinputstream
|
Pushbackreader
|
Filters: Java 1.0 class corresponding Java 1.1 class
FilterInputStream FilterReader
Filteroutputstream Filterwriter (abstract class without subclasses)
Bufferedinputstream BufferedReader (also ReadLine ())
Bufferedoutputstream BufferedWriter
DataInputStream use DataInputStream (unless you want to use ReadLine (), then you need to use a bufferedreader)
PrintStream PrintWriter
Linenumberinputstream LineNumberReader
Streamtokenizer Streamtokenizer (replace reader with builder)
Pushbackinputstream Pushbackreader
One rule is obvious: if you want to use ReadLine (), don't implement it with a datainputstream (or you'll get an error message at compile time), instead use a bufferedreader. But in addition to this, DataInputStream is still the "preferred" member of the Java 1.1 IO library.
To make the transition to printwriter more natural, it provides a builder that can take any OutputStream object. PrintWriter provides less formatting support than PrintStream, but the interfaces are almost the same.