// Program to read data from text file using
// FileReader and display it on the monitor.import java.io.*;
class FileReaderDemo
{
public static void main( String args[ ] ) throws IOException
{
// attach file to FileReader
FileReader fr = null;
try
{
fr = new FileReader( "file1.txt");
}
catch( FileNotFoundException fnfe )
{
System.out.println(" File Not found.");
return;
}
// read character from FileReader.
int ch;
System.out.println(" File Contents are : ");
while( (ch = fr.read()) != -1 )
{
System.out.print((char)ch);
}// close the file.
fr.close();
}
}
Output:File Contents are :
Learn Java Programming from www.example.com