A Monster Chain
The buffered output construct in the previous foil is of limited use since BufferedWriter has so few output methods. Instead, use the "monster" chain:
- PrintWriter out =
- new PrintWriter(
- new BufferedWriter(
- new OutputStreamWriter(
- new FileOutputStream( filename ) ) ) );
- which can be shortened somewhat by using FileWriter as shown earlier.
The PrintWriter class defines print(...) and println(...) methods for all primitive types, which unlike other Reader/Writer classes never throw exceptions.