Java InputStreamReader

An InputStreamReader is a bridge from byte streams to character streams: It reads bytes and decodes them into characters using a specified 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.

Constructor

Constructor nameDescription
InputStreamReader(InputStream in)It creates an InputStreamReader that uses the default charset.
InputStreamReader(InputStream in, Charset cs)It creates an InputStreamReader that uses the given charset.
InputStreamReader(InputStream in, CharsetDecoder dec)It creates an InputStreamReader that uses the given charset decoder.
InputStreamReader(InputStream in, String charsetName)It creates an InputStreamReader that uses the named charset.

Method

Modifier and TypeMethodDescription
voidclose()It closes the stream and releases any system resources associated with it.
StringgetEncoding()It returns the name of the character encoding being used by this stream.
intread()It reads a single character.
intread(char[] cbuf, int offset, int length)It reads characters into a portion of an array.
booleanready()It tells whether this stream is ready to be read.

Example

Output:

I love my country

The file.txt contains text "I love my country" the InputStreamReader 
reads Character by character from the file





Latest Courses