I\'ve been trying to figure out why a method I\'ve written to read objects from a file didn\'t work and realized that the available() method of ObjectInputStream gave 0 even
I found some trick! If you still want to use .available()
to read all objects to the end, you can add an integer (ex: out.writeInt(0)
) before adding each Object (ex: out.writeObject(obj)
) when you write to the file and also read integer before reading each Object. So .available()
can read byte left on file and won't be crash! Hope it helps you!