简体   繁体   中英

Reading multiple objects from file

Is there a proper way of reading objects from file using the ObjectInputStream . The examples I've seen seems to rely on that exception is caught to end the reading. While it maybe works it does not seem to be a clean solution as in exception shouldn't really happen unless there's wrong in the code.

Example 1

EOFException is thrown by the readObject() method to indicate end of stream. Ergo you must catch it to detect end of stream. QED. Never mind the exception police.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM