The Reader class in Java is an abstract class in the java.io package used for reading character streams. Its subclasses provide implementations for reading text from files, arrays, strings, and other sources.
- Implements the Readable interface to support character reading.
- Implements the Closeable interface to support resource cleanup.
Example: Reading a text file character by character using the Reader class.
Create a file named example1.txt in the working directory with the following content:

import java.io.*;
public class Geeks{
public static void main(String[] args){
try (Reader r = new FileReader("example1.txt")){
int data;
// Read characters until the end of the file
while ((data = r.read()) != -1){
System.out.print((char) data);
}
} catch (IOException e){
System.out.println(e.getMessage());
}
}
}
Output:
Hello welcome to Geeks for Geeks
Explanation: The FileReader object reads characters from the file using read() until it returns -1, indicating the end of the stream. The try-with-resources statement automatically closes the reader.
Hierarchy of Reader Class

Declaration of Reader Class
public abstract class Reader implements Readable, Closeable
Since Reader is an abstract class, it cannot be instantiated directly. Its subclasses, such as FileReader and BufferedReader, are used to create reader objects.
Constructors of Reader Class
The Reader class provides two protected constructors.
- Reader() creates a reader that uses itself as the synchronization lock.
- Reader(Object lock) creates a reader that uses the specified object as the synchronization lock.
Methods of Reader Class
Method | Description |
|---|---|
Closes the stream and releases associated resources. | |
Reads a single character or returns -1 at the end of the stream. | |
read(char[] cbuf) | Reads characters into an array. |
Reads up to len characters into an array starting at offset off. | |
Reads characters into a CharBuffer. | |
Marks the current stream position, if supported. | |
Checks whether marking is supported. | |
Resets the stream to a previous position, if supported. | |
skip(long n) | Skips characters and returns the actual number skipped. |
ready() | Checks whether the stream is ready for reading without blocking. |
transferTo(Writer out) | Transfers remaining characters to a Writer. |
nullReader() | Returns a reader containing no characters. |
of(CharSequence cs) | Creates a reader from a character sequence. |
readAllAsString() | Returns the remaining content as a String. |
readAllLines() | Returns the remaining lines as an unmodifiable list. |
Example of Reader Class Methods
The following program uses StringReader to demonstrate common Reader methods without requiring an external file.
import java.io.*;
public class Geeks{
public static void main(String[] args) throws IOException{
try (Reader r = new StringReader("Hello Geeks")){
// Check whether the stream is ready
System.out.println("Ready: " + r.ready());
// Mark the current position
r.mark(20);
// Read a single character
System.out.println("Character: " + (char) r.read());
// Return to the marked position
r.reset();
// Read characters into an array
char[] buffer = new char[5];
int count = r.read(buffer);
System.out.println("Buffer: " + new String(buffer, 0, count));
// Skip the space
r.skip(1);
// Read the remaining characters
while ((count = r.read()) != -1){
System.out.print((char) count);
}
}
}
}
Output
Ready: true Character: H Buffer: Hello Geeks
Explanation:
- ready() checks whether the reader is ready for reading.
- mark() saves the current position, and reset() returns to that position.
- read() reads individual characters or stores multiple characters in an array.
- skip(1) skips the space between Hello and Geeks.
Subclasses of Reader Class
The Reader class provides different subclasses for reading characters from various sources.
Class | Description |
|---|---|
Reads characters from files. | |
Buffers characters for efficient reading and supports reading entire lines. | |
Reads characters from a character array. | |
Provides a base class for filtering character streams. | |
Decodes byte streams into character streams. | |
Reads characters from a connected PipedWriter. | |
Reads characters from a String. |