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
Write a boolean
after each object, with the "last" object being followed by a false
. So, in your stream that you write out:
true
Then, when reading them back in, you check the flag (you know there will always be one after each object) to decide whether or not to read another one.
boolean
will be stored very compactly in a serialization stream, so it shouldn't add much to the file size.