Register Now

Login

Lost Password

Enter your email to reset your password.

BY Author

Java – The FileReader class

The FileReader is used to read characters from the file.

Declaration

class FileReader extends InputStreamReader

Constructors of FileReader (CLICK HERE)

Let’s assume that text file “alphabets.txt” is present in the current working dictionary.

Example

 import java.io.FileReader;
 import java.io.IOException;

 class FileReaderDemo 
 {
     public static void main(String args[]) throws IOException 
     {
         FileReader f = new FileReader("alphabets.txt");
         int i = f.read();
         while(i!=-1)
         {
             System.out.print((char)i);
             i = f.read();
         }
         f.close();
     }
 }

Output

ABCDEFGHIJKLMNOPQRSTUVWXYZ

 

Leave a reply