Advertisement
| FileReader(File file) |
|---|
|
This constructor creates a FileReader object to read out the contents of a file referenced by a File object. Example-:
|
| Methods | Description |
|---|---|
| available() | This method gives the remaining number of bytes available to read from this input stream. |
| read() | This method reads one character at a time from this input character stream. |
| read(char[]) | This method reads a whole character array at a time from this input character stream. |
| close() | This method closes this input stream and also frees any resources connected with this input stream. |
Advertisement
import java.io.*;
class A
{
public static void main(String... ar)
{
try
{
File file= new File("D:\\TextBook.txt");
FileReader fr= new FileReader(file);
int c;
//Reading one character a time from a file until -1 is returned
while( (c=fr.read())!=-1)
{
System.out.print((char)c);
}
fr.close();
}
catch(IOException e)
{
System.out.println(e);
}
}
}
Hello there!
FileReader class is a subclass of Reader class.
Advertisement
Advertisement
Please check our latest addition
C#, PYTHON and DJANGO
Advertisement