COMPUTER PROGRAMS ARE ONLY USEFUL if they interact with the rest of the world in some way. This interaction is referred to as input/output, or I/O. Up until now, the only type of interaction that has been covered in this textbook is interaction with the user, through either a graphical user interface or a command-line interface. But the user is only one possible source of information and only one possible destination for information. In this chapter, we'll look at others, including files and network connections. In Java, input/output involving files and networks is based on streams, which are objects that support the same sort of I/O commands that you have already used to communicate with the user in a command-line interface. In fact, standard output (System.out) and standard input (System.in) are examples of streams.
Working with files and networks requires familiarity with exceptions, which were introduced in the previous chapter. Many of the subroutines that are used can throw exceptions that require mandatory exception handling. This generally means calling the subroutine in a try...catch statement that can deal with the exception if one occurs. Some of the examples in this chapter will also use advanced techniques from Chapter 7, such as threads, Frames, and nested classes.
Contents of Chapter 10:
- Section 1: Streams, Readers, and Writers
- Section 2: Files
- Section 3: Programming with Files
- Section 4: Networking
- Section 5: Programming Networked Applications
- Programming Exercises
- Quiz on this Chapter
[ First Section | Next Chapter | Previous Chapter | Main Index ]