Class: java.io.InputStreamReader
- public class InputStreamReader
- extends Reader
charset. The charset that it uses
may be specified by name or may be given explicitly, or the platform's
default charset may be accepted.
Each invocation of one of an InputStreamReader's read() methods may cause one or more bytes to be read from the underlying byte-input stream. To enable the efficient conversion of bytes to characters, more bytes may be read ahead from the underlying stream than are necessary to satisfy the current read operation.
For top efficiency, consider wrapping an InputStreamReader within a BufferedReader. For example:
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
Methods
-
InputStreamReadertop
public InputStreamReader(InputStream in)Creates an InputStreamReader that uses the default charset. -
InputStreamReadertop
Creates an InputStreamReader that uses the named charset. -
InputStreamReadertop
public InputStreamReader(InputStream in, Charset cs)Creates an InputStreamReader that uses the given charset. -
InputStreamReadertop
public InputStreamReader(InputStream in, CharsetDecoder dec)Creates an InputStreamReader that uses the given charset decoder. -
closetop
public void close() throws IOExceptionCloses this stream and releases any system resources associated with it. If the stream is already closed then invoking this method has no effect. -
getEncodingtop
public String getEncoding()Returns the name of the character encoding being used by this stream.If the encoding has an historical name then that name is returned; otherwise the encoding's canonical name is returned.
If this instance was created with the java.io.InputStreamReader.InputStreamReader(java.io.InputStream, java.lang.String) constructor then the returned name, being unique for the encoding, may differ from the name passed to the constructor. This method will return
nullif the stream has been closed. -
readtop
public int read() throws IOExceptionReads a single character. -
readtop
public int read(char[] cbuf, int offset, int length) throws IOExceptionReads characters into a portion of an array. -
readytop
public boolean ready() throws IOExceptionTells whether this stream is ready to be read. An InputStreamReader is ready if its input buffer is not empty, or if bytes are available to be read from the underlying byte stream.
