🔥Limited Offer: Get 50% OFFon AI & Full Stack Courses🔥
Back to Java Notes
Topic #96

Java BufferedReader


BufferedReader and BufferedWriter

BufferedReader and BufferedWriter make reading and writing text files faster.

  • BufferedReader lets you read text line by line with readLine().
  • BufferedWriter lets you write text efficiently and add new lines with newLine().

These classes are usually combined with FileReader and FileWriter, which handle opening or creating the file. The buffered classes then make reading/writing faster by using a memory buffer.


Read a Text File (Line by Line)

Use BufferedReader with FileReader to read each line of a file:

Example

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

public class Main {
  public static void main(String[] args) {
    try (BufferedReader br = new BufferedReader(new FileReader("filename.txt"))) {
      String line;
      while ((line = br.readLine()) != null) {
        System.out.println(line);
      }
    } catch (IOException e) {
      System.out.println("Error reading file.");
    }
  }
}

Comparing File Reading Classes

Java gives you several ways to read files. Here's when to pick each one:

  • Scanner - best for simple text. It can split text into lines, words, or numbers (e.g., nextInt(), nextLine()).
  • BufferedReader - best for large text files. It is faster, uses less memory, and can read full lines with readLine().
  • FileInputStream - best for binary files (like images, PDFs, or audio)

Want to go beyond the notes?

Join CodingNow 2.0's Java course — live mentorship, real projects, and 100% placement support.

Enroll Now — Free Demo Available

Java BufferedReader – FAQs

Quick answers about learning Java BufferedReader in Java.

This free note from CodingNow 2.0 explains Java BufferedReader in Java — concept, syntax and worked code examples you can copy, run and revise before interviews.
Yes. Every Java topic on CodingNow 2.0, including Java BufferedReader, is 100% free with no signup required.
With focused practice, most students grasp Java BufferedReader in 1–3 days from these notes; pairing it with CodingNow 2.0's mentor-led course takes you to job-ready depth faster.
Use the code examples in this note, then ask doubts for free on the CodingNow 2.0 Community (/community) — expert instructors answer within 24 hours.
WhatsApp
Call NowEnroll Now