Reading a File using FileReader

import java.io.*
class ReadFile
{
public static void Main(String[] args) throws IOException{
int ch;

// check if file exist or not
FileReader fr=null;
try{
fr= new FileReader("TestFile")
}catch(Exception e){
System.out.println("File Not Found");
return;
}
// read the file till end of the file
while(ch=fr.read()!=-1){
System.out.print((char)ch);
//close the file
fr.close();
}
}

No comments:

Post a Comment