by Dinesh Thakur

A flow of data is often referred to as a data stream. A stream is an ordered sequence of bytes that has a SOURCE (input stream) or a DESTINATION (output stream). In simple terms, a stream can be defined as follows.


A stream is a logical device that represents the flow of a sequence of characters. Programs can get inputs from a data source by reading a sequence of characters from the input stream. Similarly, programs can produce outputs by writing a sequence of characters on to an output stream. A stream can be associated with a file, an Internet resource (For example, a socket), to a pipe or a memory buffer. Streams can be chained together so that each type of stream adds its own processing to the bytes as they pass through the stream. For the purpose of letting information flow, a program opens a stream on an information source (whether it be a file, memory, a network socket or any other source) and reads the information sequentially and uses it in the program. All streams behave in the same way even though the physical device connected to them may differ. A program can send information to an external destination by opening a stream to a destination and writing the information out sequentially. In previous chapters, we used the following two methods for taking inputs and giving outputs:


                 System.out.printIn( );

These two form the basic input and output streams, which are managed by the System class; they use the standard input and standard output streams, respectively.