Java InputStreamReader ClassLast 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 DeclarationThe following declaration shows how the InputStreamReader class is defined: Constructors of InputStreamReader ClassThe 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 ConstructorsThe following code shows how different constructors of the InputStreamReader class can be used. Methods of InputStreamReader ClassThe InputStreamReader class provides the following methods to read decoded character data.
Examples of Java InputStreamReader ClassThe following examples demonstrate how to use the Java InputStreamReader class. Example 1: Reading Data from a File Using InputStreamReaderThe 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 EncodingThe following example demonstrates how to read text using a specific character encoding with the InputStreamReader class. Output: I love my country Next TopicJava PushbackInputStream Class |
We request you to subscribe our newsletter for upcoming updates.