Name

OutputStreamWriter

Synopsis

This class is a character output stream that uses a byte output stream as the destination for its data. When characters are written to an OutputStreamWriter, it translates them into bytes according to a particular locale- and/or platform-specific character encoding and writes those bytes to the specified OutputStream. This is a very important internationalization feature in Java 1.1 and later. OutputStreamWriter supports the usual Writer methods. It also has a getEncoding( ) method that returns the name of the encoding being used to convert characters to bytes.

When you create an OutputStreamWriter, specify the OutputStream to which it writes bytes and, optionally, the name of the character encoding that should be used to convert characters to bytes. If you do not specify an encoding name, the OutputStreamWriter uses the default encoding of the default locale, which is usually the correct thing to do. In Java 1.4 and later, this class uses the charset conversion facilities of the java.nio.charset package and allows you to explicitly specify the Charset or CharsetEncoder to be used. Prior to Java 1.4, the class allows you to specify only the name of the desired charset encoding.

java.io.OutputStreamWriter

Figure 9-44. java.io.OutputStreamWriter

public class OutputStreamWriter extends Writer {
// Public Constructors
     public OutputStreamWriter(OutputStream out);  
     public OutputStreamWriter ...

Get Java in a Nutshell, 5th Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.