Thanks to visit codestin.com
Credit goes to www.geeksforgeeks.org

Open In App

Java.io.BufferedReader Class in Java

Last Updated : 30 Aug, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

The BufferedReader class in Java is used to read text from character based input streams by buffering characters. It reduces the number of I/O operations by reading large piece of data at once, making it faster than directly using FileReader or InputStreamReader. It also provides convenient methods like readLine() to read text line by line.

Constructors of BufferedReader Class 

ConstructorAction Performed
BufferedReader(Reader in)Creates a buffering character-input stream that uses a default-sized input buffer
BufferedReader(Reader in, int sz)Creates a buffering character-input stream that uses an input buffer of the specified size.

Methods of BufferedReader Class

MethodAction
close()Closes the stream and releases system resources. Further read/mark/reset/skip calls throw IOException.
mark(int readAheadLimit)Marks the current position in the stream for later reset.
markSupported()Checks if this stream supports the mark() operation (always true for BufferedReader).
read()Reads and returns a single character or -1 if end of stream is reached.
read(char[] cbuf, int off, int len)Reads characters into a portion of an array.
readLine()Reads a line of text, terminated by \n, \r or \r\n.
ready()Returns true if the stream is ready to be read without blocking.
reset()Resets the stream to the most recent mark.
skip(long n)Skips the specified number of characters.

Implementation of all methods combined

The content inside the file "file.txt" is as follows:

This is first line
this is second line

Java
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;

class GFG {

    public static void main(String[] args)
        throws IOException
    {

        // Creating object of FileReader and BufferedReader class
        FileReader fr = new FileReader("file.txt");
        BufferedReader br = new BufferedReader(fr);

        char c[] = new char[20];

        // Illustrating markSupported() method
        if (br.markSupported()) {

            // Print statement
            System.out.println(
                "mark() method is supported");

            // Illustrating mark method
            br.mark(100);
        }

        // Skipping 8 characters
        br.skip(8);

        // Illustrating ready() method
        if (br.ready()) {

            // Illustrating readLine() method
            System.out.println(br.readLine());

            // Illustrating read(char c[],int off,int len)
            br.read(c);

            for (int i = 0; i < 20; i++) {
                System.out.print(c[i]);
            }

            System.out.println();

            // Illustrating reset() method
            br.reset();
            for (int i = 0; i < 8; i++) {

                // Illustrating read() method
                System.out.print((char)br.read());
            }
        }
    }
}

Output:

mark() method is supported
first line
this is second line
This is


Input in Java
Visit Course explore course icon
Article Tags :

Explore