This module introduces you to reading and writing text in Java programs.
You will learn about:
- The vagaries of different character sets used both on different platforms and in different cultures
Writer classes, and how to connect readers and writers to input and output streams
Reader classes are similar to input streams, and writer classes are similar to output streams.
Reader classes descend from the abstract Reader class, whereas the Writer classes descend from the abstract Writer class.
Both readers and writers are divided into low-level and high-level classes.
Low-level classes communicate with I/O devices, and high-level classes communicate with the low-level ones.
Readers and writers are designed specifically for Unicode characters
and low-level readers and writers deal with chars.
The java.io package provides the following low-level Reader classes:
- FileReader: The FileReader class is used to read streams of characters from a file. This class is useful to read text files.
- CharArrayReader: The CharArrayReader class reads arrays of characters by implementing a character buffer.
The character array acts like a character input stream.
- PipedReader: The PipedReader class provides a piped character-input stream.
It should be used with a piped character-output stream so that data written to the PipedWriter will be available from this reader.
- StringReader: The StringReader class uses strings as its source of a character stream. Individual characters can be marked and read from the string.