FileReaderclass creates a Reader
that can be used to read the contents of a file.
Its two most commonly used constructors are:
FileReader(String
filePath)
FileReader(File
fileObj)
It
can throw a FileNotFoundException.
Here,
filePath is the full path name of the file, and fileObj is a File object that describes the file.
Example:
import
java.io.*;
classFilereader
{
public
static void main(String args[]) throws IOException
{
FileReader
f=new FileReader("File1.txt");
BufferedReader
b=new BufferedReader(f);
String s;
while((s=b.readLine())!=null)
System.out.println(s);
}
}
Output:
Hello
this is written to the file using print stream
Again
the next line is also written to the file
No comments:
Write comments