Java FileReader Class read() Method with Examples Last Updated : 16 Feb, 2022 Comments Improve Suggest changes Like Article Like Report The read() method of FileReader class in Java is used to read and return a single character in the form of an integer value that contains the character's char value. The character read as an integer in the range of 0 to 65535 is returned by this function. If it returns -1 as an int number, it means that all of the data has been read and that FileReader may be closed. Syntax: public abstract int read() Returns: The read() method returns a single character in the form of an integer value that contains the character's char value. It returns -1 when all of the data has been read and that FileReader may be closed. Example 1: We are calling the read() method of FileReader class to read the data from the file, this method reads the one character at a time and returns its ASCII value in the integer format. To print the actual data we must typecast it to the char. Java // Java Program to demonstrate the use of read() // method of FileReader class in Java import java.io.FileReader; public class GFG { public static void main(String args[]) { try { FileReader fileReader = new FileReader( "C:\\Users\\lenovo\\Desktop\\input.txt"); char c = (char)fileReader.read(); System.out.print(c); fileReader.close(); } catch (Exception e) { System.out.println("Error: " + e.toString()); } } } The input.txt file has the following content: Output: Example 2: Java // Java Program to demonstrate the use of read() // method of FileReader class in Java import java.io.FileReader; public class GFG { public static void main(String args[]) { try { FileReader fileReader = new FileReader( "C:\\Users\\lenovo\\Desktop\\input.txt"); int i; while ((i = fileReader.read()) != -1) System.out.print((char)i); fileReader.close(); } catch (Exception e) { System.out.println("Error: " + e.toString()); } } } After creating a FileReader, we read each character and report it to the console using the read() function. Output: Comment More infoAdvertise with us Next Article Reader read(char[]) method in Java with Examples D dikshanandre2403 Follow Improve Article Tags : Java Java-Functions java-file-handling Practice Tags : Java Similar Reads Java FileReader Class ready() Method with Examples Java FileReader class is used to read data from the data file. It returns the data in byte format as FileInputStream class. This is a character-oriented class that is used for file handling in Java. ready() Method of FileReader Class It checks if the file reader is ready to be read. It will return a 3 min read Java FileInputStream read() Method with Examples FileInputStream class in Java is useful to read data from a file in the form of a sequence of bytes. FileInputStream is meant for reading streams of raw bytes such as image data. For reading streams of characters, consider using FileReader. The read() method of InputStream class reads a byte of data 3 min read Console reader() method in Java with Examples The reader() method of Console class in Java is used to retrieve the unique Reader object which is associated with the console. This reader() method is generally used by sophisticated applications. Simple applications that require only line oriented reading, normally use readLine() method instead of 2 min read Reader read(char[]) method in Java with Examples The read(char[]) method of Reader Class in Java is used to read the specified characters into an array. This method blocks the stream till: It has taken some input from the stream.Some IOException has occurredIt has reached the end of the stream while reading. Syntax: public int read(char[] charArra 3 min read Reader read(char[]) method in Java with Examples The read(char[]) method of Reader Class in Java is used to read the specified characters into an array. This method blocks the stream till: It has taken some input from the stream.Some IOException has occurredIt has reached the end of the stream while reading. Syntax: public int read(char[] charArra 3 min read Reader read(char[]) method in Java with Examples The read(char[]) method of Reader Class in Java is used to read the specified characters into an array. This method blocks the stream till: It has taken some input from the stream.Some IOException has occurredIt has reached the end of the stream while reading. Syntax: public int read(char[] charArra 3 min read Like