CHAPTER 7
INPUT/OUTPUT AND EXCEPTION HANDLING 
CHAPTER GOALS
To read and write text files
To process command line arguments
To throw and catch exceptions
To implement programs that propagate checked exceptions
CHAPTER CONTENTS
7.1 READING AND WRITING TEXT FILES
Common Error 7.1: Backslashes in File names
Common Error 7.2: Constructing a scanner with a string
Special Topic 7.1: Reading Web Pages
Special Topic 7.2: File Dialog Boxes
Special Topic 7.3: Reading and Writing Binary Data
Special Topic 7.4: Regular Expressions
Video Example 7.1: Computing a Document's Readability ![]()
How To 7.1: Processing Text Files
Random Fact 7.1: Encryption Algorithms
Worked Example 7.1: Analyzing Baby Names ![]()
Syntax 7.1: Throwing an Exception
Syntax 7.2: Catching Exceptions
Syntax 7.4: The finally Clause
Programming Tip 7.1: Throw Early, Catch Late
Programming Tip 7.2: Do Not Squelch Exceptions
Programming Tip 7.3: Do Not Use catch and finally in the Same try Statement
Special Topic 7.5: Automatic Resource Management in Java 7
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access