Java Reference
In-Depth Information
figure 2.14
Illustration of the
throws clause
1 import java.io.IOException;
2
3 public class ThrowDemo
4 {
5 public static void processFile( String toFile )
6 throws IOException
7 {
8 // Omitted implementation propagates all
9 // thrown IOExceptions back to the caller
10 }
11
12 public static void main( String [ ] args )
13 {
14
for( String fileName : args )
{
15
try
16
{ processFile( fileName ); }
17
catch( IOException e )
18
{ System.err.println( e ); }
19
20 }
21 }
22 }
The Java library is very sophisticated and has a host of options. Here, we
examine only the most basic uses, concentrating entirely on formatted I/O. In
Section 4.5.3, we will discuss the design of the library.
2.6.1 basic stream operations
Like many languages, Java uses the notion of streams for I/O. To perform I/O
to the terminal, a file, or over the Internet, the programmer creates an associ-
ated stream . Once that is done, all I/O commands are directed to that stream.
A programmer defines a stream for each I/O target (for instance, each file
requiring input or output).
Three streams are predefined for terminal I/O: System.in , the stan-
dard input; System.out , the standard output; and System.err , the standard
error.
 
Search WWH ::




Custom Search