java filereader read a file

java filereader how to read a file tutorial example

#java #filereader #read #file #tutorial #example

public class main {

public static void main(string[] args) {

// filereader = read the contents of a file as a stream of characters.
//read() returns an int value which contains the byte value
//when read() returns -1, there is no more data to be read

try {
filereader reader = new filereader("art.txt");
int data = reader.read();
while(data != -1) {
system.out.print((char)data);
data = reader.read();
}
reader.close();

} catch (filenotfoundexception e) {
// todo auto-generated catch block
e.printstacktrace();
} catch (ioexception e) {
// todo auto-generated catch block
e.printstacktrace();
}
}
}

java filereader read a file