Java Reference
In-Depth Information
System.in is an object of type InputStream ; System.out and System.err are objects
of type PrintStream . These are byte streams, even though they are typically used to read
and write characters from and to the console. The reason they are byte and not character
streams is that the predefined streams were part of the original specification for Java, which
did not include the character streams. As you will see, it is possible to wrap these within
character-based streams if desired.
Using the Byte Streams
We will begin our examination of Java's I/O with the byte streams. As explained, at the top
of the byte stream hierarchy are the InputStream and OutputStream classes. Table 10-3
shows the methods in InputStream , and Table 10-4 shows the methods in OutputStream .
In general, the methods in InputStream and OutputStream can throw an IOException
on error. The methods defined by these two abstract classes are available to all of their sub-
classes. Thus, they form a minimal set of I/O functions that all byte streams will have.
Table 10-3 The Methods Defined by InputStream
 
Search WWH ::




Custom Search