Monday, 19 October 2015

Reading from a file using FileReader in java

import java.io.*;
public class First {

public static void main(String[] args) throws IOException {
// TODO Auto-generated method stub
int ch;
FileReader fr = null;
try{
fr = new FileReader("test.txt");
}
catch(FileNotFoundException fe){
System.out.println("File Not found");
}
//finally{
// fr.close();
// }
while((ch=fr.read())!=-1){
System.out.println((char)ch);
}
fr.close();
}

}


Output:-
P
e
r
f
o
r
m
a
n
c
e
 
B
l
o
g




Text file contents:-
Performance Blog

No comments:

Post a Comment