Name

InputStreamReader

Synopsis

This class is a character input stream that uses a byte input stream as its data source. It reads bytes from a specified InputStream and translates them into Unicode characters according to a particular platform- and locale-dependent character encoding. This is an important internationalization feature in Java 1.1 and later. InputStreamReader supports the standard Reader methods. It also has a getEncoding( ) method that returns the name of the encoding being used to convert bytes to characters.

When you create an InputStreamReader, you specify an InputStream from which the InputStreamReader is to read bytes and, optionally, the name of the character encoding used by those bytes. If you do not specify an encoding name, the InputStreamReader uses the default encoding for 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 CharsetDecoder to be used. Prior to Java 1.4, the class allows you to specify only the name of the desired charset encoding.

java.io.InputStreamReader

Figure 9-26. java.io.InputStreamReader

public class InputStreamReader extends Reader {
// Public Constructors
     public InputStreamReader(InputStream in);  
     public InputStreamReader(InputStream in, String charsetName) throws UnsupportedEncodingException; ...

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.