7.1 What is a stream ? 

Previous Index Next 


Input and output in Java is organized around the concept of streams. A stream is a sequence of items, usually 8-bit bytes, read or written over the course of
time.

In the java.io package, all input is done through subclasses of the abstract class InputStream, and all output is done through subclasses of the abstract
class OutputStream. The one exception to this rule is the class RandomAccessFile, which handles files that allow random access and perhaps intermixed
reading and writing of the file.

For an input stream, the source of data might be a file, a String, an array of bytes, or bytes written to an output stream (typically by another thread). There
are also "filter input streams" that take data from another input stream and transform or augment the data before delivering it as input. For example, a
LineNumberInputStream passes bytes through verbatim but counts line terminators as they are read.

For an output stream, the sink of data might be a file, an array of bytes, or a buffer to be read as an input stream (typically by another thread). There are
also "filter output streams" that transform or augment data before writing it to some other output stream.



Sources