The FileReader class is used to create a character based stream that reads from file. The FileReader class is inherited from InputStreamReader and this will throw a FileNotFoundException.
Let us look at the following example that will open the text file and reads the content and display it.
Example:
/**
From FileReaderExample.java
*/
import java.io.FileReader;
/**
*
* @author JavaHotSpot
*/
public class FileReaderExample
{
public static void main(String args[])
{
try
{
char ch[]=new char[1000];
int size;
FileReader fr= new FileReader("C:\\file1.txt");
size=fr.read(ch);
System.out.println("File Content is \n"+new String(ch,0,size));
fr.close();
}
catch(Exception ex)
{
System.err.println(ex);
}
}
}
Output:
File Content is
This is example of fileoutputstream class
Related Articles:
FileInputStream
FileOutputStream
InputStreamReader
FileWriter
BufferedInputStream
BufferedOutputStream
BufferedReader
BufferedWriter
DataInputStream
DataOutputStream
ObjectInputStream
ObjectOutputStream
Related Articles:
FileInputStream
FileOutputStream
InputStreamReader
FileWriter
BufferedInputStream
BufferedOutputStream
BufferedReader
BufferedWriter
DataInputStream
DataOutputStream
ObjectInputStream
ObjectOutputStream