I am thinking up a way to get around the whole bad habit that is using an infinite loop to read in objects. My algorithm involves iteratively checking
if (FileInputStream("myFile.ser").available() != 0)
and then deserialize the next
object. Otherwise, I would close the file.
I want to know if this is the correct way to go about this.
I have read this question's answers: May the FileInputStream.available foolish me? and don't know if, by empty, they mean that the read pointer is at the end-of-file.
In other words, Could I trust FileInputStream.available()
to check how much data is still available for reading from the file?