Home / Questions / How does checking for the end-of-file (EOF) differ between reading a text file with BufferedReader and reading a binary file with DataInputStream?
Explanatory Question

How does checking for the end-of-file (EOF) differ between reading a text file with BufferedReader and reading a binary file with DataInputStream?

👁 1 Views
📘 Detailed Answer
🕒 Easy to Read
Read the answer carefully and go through the related questions on the right side to improve your understanding of this topic.

Answer with Explanation

When reading a text file with a BufferedReader, the readLine() method returns null when it reaches the end of the file, which can be checked in a loop condition. When reading a binary file with a DataInputStream, the read methods do not return a special value; instead, an EOFException is thrown when an attempt is made to read past the end of the file, which must be caught to handle the EOF condition.