Text Processing
java.io Library
- http://java.sun.com/j2se/1.5.0/docs/api/
- provides the ability to do input and output
- byte, character, buffered, data, and object streams
- BufferedReader - read a line of text at a time
- PrintWriter - output methods similar to System.out
- File - represents a file or directory
- CopyLines.java
- handling exceptions
- the finally block
- FileNotFoundException
String Manipulation
How would you modify CopyLines to replace all instances of the word super with the word ultra?
- String objects are immutable -- they cannot change
- StringBuffer - a mutable sequence of characters
- StringBuilder - also a mutable sequence of characters
- StringBuilder is not thread safe. It is more efficient when the string is accessed by a single thread, but should not be used when multiple threads modify the same object.
- String - methods return the new string (a different object)
- replaceAll
- split
- substring
- Regular expressions
- Pattern
- *, +, ?
- Exercise: find and replace all phone numbers of the form (123)456-7890 with XXX.