Java BufferedReader ClassLast Updated : 27 Jan 2026 The BufferedReader class in Java is used to read text efficiently from a character-based input stream. In this chapter, we will learn what the BufferedReader class is, why it is used, its declaration, constructors, important methods, and how to read data from files and the console using examples. What is BufferedReader Class in Java?The BufferedReader class is a character-based input stream that provides buffering for another Reader, making the reading process faster and more efficient. It is commonly used to read text data line by line using the readLine() method. By reducing the number of direct I/O operations, it improves performance when reading large amounts of text. The BufferedReader class extends the Reader class. BufferedReader Class DeclarationThe following declaration shows how the BufferedReader class is defined: Constructors of BufferedReader ClassThe BufferedReader class provides constructors to create a buffered character input stream. 1. BufferedReader(Reader rd)This constructor creates a buffered reader that uses the default buffer size. Syntax: Here is the syntax: 2. BufferedReader(Reader rd, int size)This constructor creates a buffered reader with a specified buffer size. Syntax: Here is the syntax: Example of BufferedReader Class ConstructorsThe following code shows how the constructors of the BufferedReader class are used. Methods of BufferedReader ClassThe BufferedReader class provides methods to read character data efficiently.
Examples of Java BufferedReader ClassThe following examples demonstrate different ways to read data using the Java BufferedReader class. Example 1: Reading Data from a File Using BufferedReaderThe following example demonstrates how to read text from a file using the BufferedReader class. File Content (testout.txt): Welcome to TpointTech. Output: Welcome to TpointTech. Example 2: Reading Data from Console Using BufferedReaderThe following example demonstrates how to read input from the console using InputStreamReader and BufferedReader. Output: Enter your name: Nakul Jain Welcome Nakul Jain Next TopicJava CharArrayReader Class |
We request you to subscribe our newsletter for upcoming updates.