posted 12 years ago
To add to what Rob has explained... please note that the wrapper output stream (like ObjectOutputStream) may have some buffered data, yet to be written to the wrapped stream. Usually, the last bit of leftover data is flushed while closing the stream. So, if you happen to close the wrapped stream first, you might simply lose it (even if you don't encounter an IOException, that is).
Thumb rule - Just close the outermost streams, and they will have a cascading effect on the wrapped ones.