181k views
4 votes
Assume that input file references a Scanner object that was used to open a file. Which of the following while loops shows the correct way to read data from the file until the end of the file is reached?a. while (inputFile != null)b. while (!inputFile.EOF)c. while (inputFile.hasnextInt())d. while (inputFile.nextLine == " ")

1 Answer

4 votes

while (!inputFile.EOF) loops shows the correct way to read data from the file until the end of the file is reached.

b. while (!inputFile.EOF)

Step-by-step explanation:

Normally to read an input files as loop the program reads till end of file mark been seen. A loop been executed till an EOF is reached.

End user has to write a logic in software languages which should have a loop and ready a bit or set of bits which depends of end user technology and stop reading till end of file which is called EOF = true.

If EOF is not true then end user program loop never ends and program is either hang or bug or goes to really task.

End user has check either EOF = True or files size reach to end of bytes. Whichever comes first.

Otherwise if EOF is not true then it is corrupted files.

User FormigaNinja
by
7.6k points