VOOZH about

URL: https://www.geeksforgeeks.org/java/java-io-reader-class-java/

⇱ Java Reader Class - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Java Reader Class

Last Updated : 10 Dec, 2025

The Reader class in Java is an abstract class for reading character streams. Its subclasses (FileReader, BufferedReader) provide implementations, with read() being the main method to read characters.

  • It implements the Readable interface that defines the read(CharBuffer cb) method.
  • It implements the Closeable interface that defines the close() method to release resources.
👁 reader_
Reader

Declaration of Reader Class

Declaration of Reader class is given below:

public abstract class Reader implements Readable, Closeable

Example: Read a text file character by character using the Reader class.

Output :

👁 Output
output

Note: To ensure the program runs correctly, create a file named example1.txt in the working directory.

Add the following content to the file, or you can add any text.

Hello welcome to Geeks for Geeks

Save the file and run the program. The program will read and display the contents of example1.txt as output.

Constructors of Reader Class

There are two constructors used with Java Reader Class as mentioned below:

  • protected Reader():Creates a new character-stream reader whose critical sections will synchronize on the reader itself.
  • protected Reader(Object lock): Creates a new character-stream reader whose critical sections will synchronize on the given object.

Methods of Java Reader Class

MethodDescription
abstract void close()Closes the stream and releases resources.
void mark(int readAheadLimit)Marks the current position in the stream.
boolean markSupported()Checks if mark/reset operations are supported.
int read()Reads a single character from the stream. Returns -1 if the end is reached.
int read(char[] cbuf)Reads multiple characters into an array.
abstract int read(char[] cbuf, int off, int len)Reads a portion of the array starting at offset off for length len.
int read(CharBuffer target)Reads characters into a CharBuffer object.
void reset()Resets the stream to the most recent mark position.
long skip(long n)Skips the specified number of characters.

Example: The below program demonstrate the working of various functionalities of the Reader class in Java.

Output:

👁 Output
Output

Implementation of Reader Classes

Some of the implementations of Reader classes in Java are mentioned below:

Comment
Article Tags: