Java ReaderLast Updated : 24 Jan 2026 The Reader class in Java is an abstract class used for reading character streams. In this chapter, we will learn what the Reader class is, why it is used, its declaration, constructors, important methods, and how to read character data using examples. What is Reader Class in Java?The Reader class is an abstract class for reading data in the form of characters, and it is used as the base class for all character input stream classes. It provides common methods to read characters, character arrays, and strings. Classes such as BufferedReader, FileReader, InputStreamReader, and StringReader extend the Reader class to provide concrete implementations. Java Reader Class DeclarationThe following declaration shows how the Reader class is defined in Java. Fields of Reader ClassThe Reader class contains a field used for synchronization.
Constructors of Reader ClassThe Reader class provides protected constructors that are used by its subclasses. 1. Reader()This constructor creates a new character stream reader whose critical sections synchronize on the reader itself. Syntax: Here is the syntax of this constructor: 2. Reader(Object lock)This constructor creates a new character stream reader whose critical sections synchronize on the specified lock object. Syntax: Here is the syntax of this constructor: Example of Reader Class ConstructorsThe following example shows how the constructors of the Reader class are used indirectly through its subclasses. Methods of Reader ClassThe Reader class provides methods to read character data from input streams.
Examples of Java Reader ClassThe following examples demonstrate how the Reader class is used through its subclasses. Example 1: Reading Characters from a File Using FileReaderThis example demonstrates how to read characters from a file using the FileReader class. file.txt: I love my country Output: I love my country Example 2: Reading Data Using BufferedReaderThis example demonstrates how to read text efficiently using the BufferedReader class. Output: I love my country Next TopicJava FileWriter class |
We request you to subscribe our newsletter for upcoming updates.