Java Reference
In-Depth Information
Most programmers use a variable identifier such as myIn or dataIn to hold
the input data read by the BufferedReader class. As shown in Figure 3-11 on the
previous page, line 20 uses the identifier dataIn. When assigned by one of several
readLine() methods, dataIn will contain the new data from System.in wrapped
in the InputStreamReader. Figure 3-12 shows the flow of the data stream.
user enters data
program receives
stream of bytes from
the System.in buffer
System.in
Buffer
InputStreamReader
decodes bytes into
characters
InputStreamReader
program receives stream
of characters from the
InputStreamReader and
prepares it for storage
BufferedReader
Stored Data
data is stored in
variable location
FIGURE 3-12
The following step enters code to instantiate the BufferedReader.
To Enter Code to Instantiate the BufferedReader
1. With the insertion point on line 20 in the coding window, enter lines 20
and 21, as shown in Figure 3-11 on the previous page.
The BufferedReader code is displayed in line 20 (Figure 3-13). Line 21 is a
blank line.
Search WWH ::




Custom Search