What is the best way to fully read a stream of objects from a file in Java?

后端 未结 4 1410
星月不相逢
星月不相逢 2021-01-14 17:33

I\'m creating a potentially long log of objects and do not want to keep them all in memory before writing to a file, so I can\'t write a serialized collection of the objects

4条回答
  •  孤独总比滥情好
    2021-01-14 18:00

    Your code is incorrect. readObject() doesn't return null at EOS, it throws EOFException. So catch it. Null is returned if you wrote a null. You don't need all the booleans or marker objects suggested above.

提交回复
热议问题