In addition to the possibility of an IOException being generated during I/O, there
is also the possibility of a ClassNotFoundException being generated, so we must
either handle this exception ourselves or throw it. A further consideration that needs
to be made is how we detect end-of-file, since there is no equivalent of the Scanner
class’s hasNext method for use with object streams. We could simply use a for
loop to read back the number of objects we believe that the file holds, but this would
be very bad practice in general (especially as we may often not know how many
objects a particular file holds).