improve performance if they also override other methods.
Writer also implements the java.lang.Appendable interfacesee page 332. The append(charc)
method is equivalent to write(c); the append methods that take a CharSequence are equivalent to
passing the String representations of the CharSequence objects to the write(Stringstr) method.
20.3.3. Character Streams and the Standard Streams
The standard streams System.in, System.out, and System.err existed before the character streams
were invented, so these streams are byte streams even though logically they should be character streams. This
situation creates some anomalies. It is impossible, for example, to replace System.in with a
LineNumberReader to keep track of the standard input stream's current line number. By attaching an
InputStreamReaderan object that converts a byte input stream to a character input streamto
System.in, you can create a LineNumberReader object to keep track of the current line number (see
"LineNumberReader" on page 527). But System.in is an InputStream, so you cannot replace it with a
LineNumberReader, which is a type of Reader, not an InputStream.
System.out and System.err are PrintStream objects. PrintStream has been replaced by its
equivalent character-based version PrintWriter. Generally, you should avoid creating PrintStream
objects directly. You'll learn about the Print stream classes in Section 20.5.8 on page 525.
20.4. InputStreamReader and OutputStreamWriter
The conversion streams InputStreamReader and OutputStreamWriter TRanslate between
character and byte streams using either a specified character set encoding or the default encoding for the local
system. These classes are the "glue" that lets you use existing 8-bit character encodings for local character sets
in a consistent, platform-independent fashion. An InputStreamReader object is given a byte input stream
as its source and produces the corresponding UTF-16 characters. An OutputStreamWriter object is
given a byte output stream as its destination and produces encoded byte forms of the UTF-16 characters
written on it. For example, the following code would read bytes encoded under ISO 8859-6 for Arabic
characters, translating them into the appropriate UTF-16 characters:
public Reader readArabic(String file) throws IOException {
InputStream fileIn = new FileInputStream(file);
return new InputStreamReader(fileIn, "iso-8859-6");
}
By default, these conversion streams will work in the platform's default character set encoding, but other
encodings can be specified. Encoding values were discussed in "Character Set Encoding" on page 320; they
can be represented by name or a Charset, or by a CharsetDecoder or CharsetEncoder object from
the java.nio.charset package.
publicInputStreamReader(InputStream in)
Creates an InputStreamReader to read from the given InputStream
using the default character set encoding.
publicInputStreamReader(InputStream in, Charset c)