GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Java Tutorial
  • Advanced Java
  • Interview Questions
  • Exercises
  • Examples
  • Quizzes
  • Projects
  • Cheatsheet
  • DSA in Java
  • Java Collection
  • Introduction3 min read
  • Variables2 min read
  • Data Types7 min read
  • Operators7 min read

This view

  • Original page
  • New address

GeezerVison is showing www.geeksforgeeks.org — Java.io.BufferedReader Class in Java - GeeksforGeeks

geeksforgeeks
search icon
  • Courses
  • Tutorials
  • Interview Prep
  • Java Tutorial
  • Advanced Java
  • Interview Questions
  • Exercises
  • Examples
  • Quizzes
  • Projects
  • Cheatsheet
  • DSA in Java
  • Java Collection

Java.io.BufferedReader Class in Java

Last Updated : 6 Oct, 2026

The BufferedReader class in Java helps read text efficiently from files or user input. It stores data in a buffer, making reading faster and smoother instead of reading one character at a time.

  • Faster Reading: Reads large chunks of data at once, reducing the number of read operations.
  • Easy to Use: Can read text line by line using the readLine() method.

Class Declaration

public class BufferedReader extends Reader

Sample.txt

Welcome to GeeksforGeeks.
BufferedReader reads text efficiently.
Learning Java is easy.

The BufferedReader class extends the Reader class, which means it is a subclass specialized for character input with buffering capabilities.

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

public class GFG {

    public static void main(String[] args)
    {

        try (BufferedReader reader = new BufferedReader(
                 new FileReader("sample.txt"))) {

            String line;

            while ((line = reader.readLine()) != null) {
                System.out.println(line);
            }
        }
        catch (IOException e) {
            System.out.println(
                "An error occurred while reading the file: "
                + e.getMessage());
        }
    }
}

Output:

Screenshot-2026-10-05-173431
output

Explanation: The program uses BufferedReader with FileReader to read text line by line from the file sample.txt. The readLine() method continues until it reaches the end of the file (null).

Constructor of BufferedReader Class

1. BufferedReader(Reader in): Creates a buffered character input stream using the specified reader.

BufferedReader br = new BufferedReader(new FileReader("file.txt"));

2. BufferedReader(Reader in, int size): Creates a buffered character input stream with a custom buffer size.

BufferedReader br = new BufferedReader(new FileReader("file.txt"), 8192);

Example: Reading Text from a File

Java
import java.io.*;

public class GFG{
    
    public static void main(String[] args)
        throws IOException
    {
        BufferedReader reader = new BufferedReader(
            new InputStreamReader(System.in));

        System.out.print("Enter your name: ");
        String name = reader.readLine();

        System.out.println("Hello, " + name + "!");
    }
}

Output:

output
output

Common Methods of BufferedReader Class

MethodAction
close()Closes the stream and releases associated resources.
mark(int readAheadLimit)Marks the current position so that the stream can later be reset to this position.
markSupported()Checks whether the stream supports the mark() operation. BufferedReader supports marking.
read()Reads a single character and returns -1 when the end of the stream is reached.
read(char[] cbuf, int off, int len)Reads characters into a portion of the specified character array.
readLine()Reads a line of text and returns null when the end of the stream is reached.
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.
lines()Returns a Stream<String> containing the lines read from the BufferedReader.
Comment

Explore

    Basics
    • Introduction3 min read
    • Variables2 min read
    • Data Types7 min read
    • Operators7 min read
    • Decision Making5 min read
    • Methods7 min read
    • Arrays7 min read
    • Strings5 min read
    OOP & Interface
    • Introduction6 min read
    • Constructors6 min read
    • Encapsulation3 min read
    • Inheritance8 min read
    • Polymorphism5 min read
    • Abstraction5 min read
    • Interfaces8 min read
    Collections
    • Collection class9 min read
    • Collection Interface5 min read
    • List Interface8 min read
    • Set Interface5 min read
    • Queue Interface5 min read
    • Map Interface in Java6 min read
    • Iterator4 min read
    Advance Java Concepts
    • Exception handling6 min read
    • Java Multithreading Tutorial3 min read
    • Synchronization in Java9 min read
    • File handling6 min read
    • Method References3 min read
    • Java 8 Stream Tutorial7 min read
    • Memory Management4 min read
    • Garbage Collection in Java6 min read
    • Networking6 min read
    • JDBC5 min read
    Practice Java
    • Interview Questions15+ min read
    • Programs6 min read
    • Practice Problems5 min read
    • Quiz1 min read
    • Project Ideas15+ min read
    Courses
    • Java Backend Course2 min read
    • Placement 360 Course2 min read
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.