Java FileReader ClassLast Updated : 27 Jan 2026 The FileReader class in Java is used to read character-oriented data from a file. In this chapter, we will learn what the FileReader class is, why it is used, its declaration, constructors, important methods, and how to read data from files using examples. What is FileReader Class in Java?The FileReader class is a character-based input stream that is used to read data from a file, and it is commonly used for file handling in Java. It reads data character by character and internally uses byte streams to decode characters. Unlike FileInputStream, FileReader is suitable for reading text data rather than raw binary data. Java FileReader Class DeclarationThe following declaration shows how the FileReader class is defined in Java. Constructors of FileReader ClassThe FileReader class provides constructors to open files in read mode. 1. FileReader(String file)This constructor opens the specified file using the file name provided as a string. If the file does not exist, it throws FileNotFoundException. Syntax: Here is the syntax: 2. FileReader(File file)This constructor opens the specified file using a File object. If the file does not exist, it throws FileNotFoundException. Syntax: Here is the syntax: Example of FileReader Class ConstructorsThe following code shows how the constructors of the FileReader class are used. Methods of FileReader classThe FileReader class provides methods to read character data from a file.
Examples of Java FileReader ClassThe following examples demonstrate how to read data from a file using the FileReader class. Example 1: Reading File Character by CharacterThe following example demonstrates how to read a text file character by character using the FileReader class. File Content (testout.txt): Welcome to TpointTech. Output: Welcome to TpointTech. Example 2: Reading File Using File ObjectThe following example demonstrates how to read data from a file using a File object with the FileReader class. Output: Welcome to TpointTech. Next TopicJava BufferedWriter Class |
We request you to subscribe our newsletter for upcoming updates.