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 Java FileReader Class read() Method 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 FileReader Class close() Method with Examples The close() method of FileReader class in Java is used to close the file reader. We can't utilize the reader to read data after the close() method is executed. This procedure closes the stream and frees all associated system resources. Calling read(), ready(), mark(), reset(), or skip() after this m 2 min read Java FileReader Class getEncoding() Method with Examples The getEncoding() method of FileReader Class in Java is used to return the name of the current stream's character encoding. If the stream is utilizing a historical encoding name, it will be returned; otherwise, the canonical encoding name of the stream will be returned. Syntax: public String getEnco 2 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 Reader close() method in Java with Examples The close() method of Reader Class in Java is used to close the stream and release the resources that were busy in the stream, if any. This method has following results: If the stream is open, it closes the stream releasing the resources If the stream is already closed, it will have no effect. If an 2 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 StringReader close() method in Java with Examples The close() method of StringReader Class in Java is used to close the stream and release the resources that were busy in the stream, if any. This method has following results: If the stream is open, it closes the stream releasing the resources If the stream is already closed, it will have no effect. 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 File setReadOnly() method in Java with examples The setReadOnly() method is a part of File class. The setReadOnly() function marks the specified file or directory such that only read operations are allowed on the file or directory. Function Signature: public boolean setReadOnly() Syntax: file.setReadOnly() Parameters: The function do not requires 2 min read CharBuffer read() methods in Java with Examples The read() method of java.nio.CharBuffer Class is used to read characters into the specified character buffer. The buffer is used as a repository of characters as-is: the only changes made are the results of a put operation. No flipping or rewinding of the buffer is performed. Syntax: public int rea 4 min read Like