Monday 7 October 2013

Read File Using FileReader

import java.io.File;
import java.io.FileReader;
import java.io.IOException;

public class ReadFileEx {

public static void main(String[] args) {

File f = new File("d:/ram.txt");

FileReader fr = null;

try {
fr = new FileReader(f);

for (int val = fr.read(); val!= -1;val=fr.read()) {
System.out.print((char) val);
}

} catch (IOException e) {
e.printStackTrace();
} finally {
try {
if (fr != null)
fr.close();
} catch (IOException ex) {
ex.printStackTrace();
}
}
}
}

No comments:

Post a Comment