go to previous page   go to home page   go to next page        


Yes. For example, buffering is useful for output as well as input.

Character Streams and Byte Streams

Character streams are intended exclusively for character data. Byte streams are intended for general purpose input and output. Of course, fundamentally all data consist of patterns of bits grouped into 8-bit bytes. So, logically all streams could be called "byte streams". However streams that are intended for bytes that represent characters are called "character streams" and all others are called "byte streams".

Character streams are optimized for character data and perform some other useful character-oriented tasks (more on this later). Often the source or destination of a character stream is a text file, a file that contains bytes that represent characters.

So far in these chapters, programs have done IO only with character data (usually with the keyboard as the source and the monitor as the destination). However, data sources and destinations often contain non-character data. For example, the bytecode file created by the Java compiler contains machine instructions for the Java virtual machine. These are not intended to represent characters, and input and output of them must use byte streams.


Think of another type of file that contains data other than characters.