Java FileReader (read a file) 📖

Описание к видео 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();
}
}
}

Комментарии

Информация по комментариям в разработке