Java Reader

Last Updated : 24 Jan 2026

The Reader class in Java is an abstract class used for reading character streams.

In this chapter, we will learn what the Reader class is, why it is used, its declaration, constructors, important methods, and how to read character data using examples.

What is Reader Class in Java?

The Reader class is an abstract class for reading data in the form of characters, and it is used as the base class for all character input stream classes.

It provides common methods to read characters, character arrays, and strings. Classes such as BufferedReader, FileReader, InputStreamReader, and StringReader extend the Reader class to provide concrete implementations.

Java Reader Class Declaration

The following declaration shows how the Reader class is defined in Java.

Fields of Reader Class

The Reader class contains a field used for synchronization.

Modifier and TypeFieldDescription
protected ObjectlockThe object used to synchronize operations on this stream.

Constructors of Reader Class

The Reader class provides protected constructors that are used by its subclasses.

1. Reader()

This constructor creates a new character stream reader whose critical sections synchronize on the reader itself.

Syntax:

Here is the syntax of this constructor:

2. Reader(Object lock)

This constructor creates a new character stream reader whose critical sections synchronize on the specified lock object.

Syntax:

Here is the syntax of this constructor:

Example of Reader Class Constructors

The following example shows how the constructors of the Reader class are used indirectly through its subclasses.

Methods of Reader Class

The Reader class provides methods to read character data from input streams.

Modifier and TypeMethodDescription
abstract voidclose()It closes the stream and releases any system resources associated with it.
voidmark(int readAheadLimit)It marks the present position in the stream.
booleanmarkSupported()It tells whether this stream supports the mark() operation.
intread()It reads a single character.
intread(char[] cbuf)It reads characters into an array.
abstract intread(char[] cbuf, int off, int len)It reads characters into a portion of an array.
intread(CharBuffer target)It attempts to read characters into the specified character buffer.
booleanready()It tells whether this stream is ready to be read.
voidreset()It resets the stream.
longskip(long n)It skips characters.

Examples of Java Reader Class

The following examples demonstrate how the Reader class is used through its subclasses.

Example 1: Reading Characters from a File Using FileReader

This example demonstrates how to read characters from a file using the FileReader class.

file.txt:

I love my country

Output:

I love my country

Example 2: Reading Data Using BufferedReader

This example demonstrates how to read text efficiently using the BufferedReader class.

Output:

I love my country