|
Is it possible for a program to use several input and several output streams? A good answer might be:Yes. For example, a text editor typically does output to both the monitor and to a disk file. Its input comes from both a disk file and the keyboard. |
Processing StreamsA processing stream operates on the data supplied by another stream. Often the processing stream performs buffering on the data coming from another stream. A buffer is a section of memory used as a work area. For example, disk file data usually is delivered by the operating system in blocks of 512 bytes at a time. Usually this data is buffered and delivered to a program in more suitable sizes. You have seen this before. In the following, the keyboard sends data to the InputStream System.in which is connected to a InputStreamReader stream which is connected to a BufferedReader stream. System.in is a stream object that the Java system automatically creates when your program starts running.
The data is transformed along the way.
The raw bytes from the keyboard are grouped
together into a String object that the program
reads using This may seem like an unnecessary complication. But java.io gives you a collection of parts that can be assembled to do nearly any IO task you need. |
QUESTION 4:Might several connected streams be used for output? Click Here after you have answered the question |