Character Streams
Java 1.1 introduced Reader and Writer classes for character streams, which are used to read/write text files.
To construct a character output stream, for example:
- PrintWriter out =
- new PrintWriter(
- new OutputStreamWriter(
- new FileOutputStream( filename ) ) );
The OutputStreamWriter constructor takes a byte stream and converts it to a character stream. As a shortcut, use
- PrintWriter out =
- new PrintWriter(
- new FileWriter( filename ) );
- where FileWriter is a subclass of OutputStreamWriter.