Working with the Stream Classes

   

The java.io package provides different input and output streams for reading and writing data. There are also two separate sets of stream classes. Prior to JDK 1.1, the input and output classes only supported 8-bit byte streams. Starting with JDK 1.1, 16-bit Unicode character streams were also being supported. This was very important because character streams have these important characteristics:

  • They can deal with any character in the Unicode set.

  • They use buffering internally.

  • Internationalization is easier because they don't rely on a specific encoding.

The byte and character streams are really a distinct set of classes. Most of the functionality for byte streams is located in the base InputStream and OutputStream classes. The functionality for character streams is located in the abstract base classes java.io.Reader and java.io.Writer. It's actually pretty easy to remember which streams are for byte data and which are for character data. The byte- related streams end with an InputStream or OutputStream. The streams that are for character data end with Reader or Writer.

Most of the functionality for byte streams also exists in the character stream. Both have input and output streams and both have specialized subclasses. When deciding on which stream you need to use in a program, first determine whether you are dealing with binary or character data. After that, you can focus your decision on either the byte stream classes or the character stream classes exclusively. Character streams are dealt with a little later in this chapter. For now, take a look at byte streams.

   


Special Edition Using Java 2 Standard Edition
Special Edition Using Java 2, Standard Edition (Special Edition Using...)
ISBN: 0789724685
EAN: 2147483647
Year: 1999
Pages: 353

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net