Java InputStreamReader Class

Last Updated : 28 Jan 2026

The InputStreamReader class in Java is used to convert byte streams into character streams using a specified character encoding.

In this chapter, we will understand what the InputStreamReader class is, why it is used, its declaration, constructors, important methods, and how to read character data from byte streams using examples.

What is InputStreamReader Class in Java?

The InputStreamReader class acts as a bridge between byte streams and character streams. It reads raw bytes from an input stream and decodes them into characters using a specified charset.

The character encoding can be explicitly defined, provided through a decoder, or taken from the platform’s default charset. InputStreamReader is commonly used when reading text data from files, sockets, or other byte-based sources.

InputStreamReader Class Declaration

The following declaration shows how the InputStreamReader class is defined:

Constructors of InputStreamReader Class

The InputStreamReader class provides multiple constructors to handle different character encodings.

1. InputStreamReader(InputStream in)

This constructor creates an InputStreamReader that uses the platform’s default character encoding.

Syntax:

Here is the syntax:

2. InputStreamReader(InputStream in, Charset cs)

This constructor creates an InputStreamReader that uses the specified charset.

Syntax:

Here is the syntax:

3. InputStreamReader(InputStream in, CharsetDecoder dec)

This constructor creates an InputStreamReader that uses the given charset decoder.

Syntax:

Here is the syntax:

4. InputStreamReader(InputStream in, String charsetName)

This constructor creates an InputStreamReader that uses the named charset.

Syntax:

Here is the syntax:

Example of InputStreamReader Class Constructors

The following code shows how different constructors of the InputStreamReader class can be used.

Methods of InputStreamReader Class

The InputStreamReader class provides the following methods to read decoded character data.

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.

Examples of Java InputStreamReader Class

The following examples demonstrate how to use the Java InputStreamReader class.

Example 1: Reading Data from a File Using InputStreamReader

The following example demonstrates how to read character data from a file using the InputStreamReader class.

Output:

I love my country

Example 2: Reading File Data Using UTF-8 Encoding

The following example demonstrates how to read text using a specific character encoding with the InputStreamReader class.

Output:

I love my country