![]() |
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
The input.txt file has the following content: Output: Example 2: Java
After creating a FileReader, we read each character and report it to the console using the read() function. Output: |
Reffered: https://www.geeksforgeeks.org
Java |
Related |
---|
![]() |
![]() |
![]() |
![]() |
![]() |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 10 |