This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
hi all, the code below only reads from halfway through the file, and at the end it throws an EOFException. i thought that "while (os.readObject() != null)" would prevent this, but apparently i need to use something else. can someone help? thanks.
Take a few minutes and become familiar with the Java API documentation for java.io.ObjectInputStream. You will see that readObject() does not return null on EOF, it throws various exceptions. I am not a fan of using exceptions to report expected conditions like EOF, so I recommend that if you are going to store an unknown number of objects, store them in a Collection of some sort and serialize that. Then you can read the all the objects in with a single call and an exception will indicate an exceptional condition.