This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes expected end of file and unexpected end of file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Beginning Java
Bookmark "expected end of file and unexpected end of file" Watch "expected end of file and unexpected end of file" New topic
Author

expected end of file and unexpected end of file

Java Daisuki
Greenhorn

Joined: Jul 30, 2005
Posts: 6
Hello, I do not understand the difference between an expected end of file and unexpected end of file. Reading under the section of Exception handling. It said that the method differentiates between expected and unexpected enf of file,,,

What does it mean ?
jiju ka
Ranch Hand

Joined: Oct 12, 2004
Posts: 306
Where do you read it? Can you post the url from where you read it?
Java Daisuki
Greenhorn

Joined: Jul 30, 2005
Posts: 6
This section is found in my textbook called Computig concepts with Java essential from Cay Horstmann, John Wiley and son Inc.

Quote :
Java Daisuki
Greenhorn

Joined: Jul 30, 2005
Posts: 6
Page 570, Quote : Note that the method differenciate between the expected end of ile and an unexpected end of ile, all files must come to an end. The method is prepared for the case that the end of file has been reached before the start of record. In that case, the method simply returns false. However if the file ends in the middle of a record, then the method throws an excpetion.

This section does not make sense to me.
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14194
    
  20

The file that the book is talking about consists of records. There is, ofcourse, a finite number of records in the file. Normally, the file ends after the last record. The method returns false if the end of the file has been reached and there are no more records to read (this is the normal, expected end-of-file situation).

However, something could be wrong with the file. If the file ends in the middle of a record, then something is wrong. In a normal situation, this is not what's supposed to happen, so it's an unexpected end-of-file. In that case the method throws an exception, to indicate that something is wrong.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
 
Consider Paul's rocket mass heater.
 
subject: expected end of file and unexpected end of file