In serialization, normally flush is not used. But its better to use flush because its a security measure that is taken to ensure that any data remaining on the stream is written on the file. close() does the same thing but it is not meant to check the streams properly.
flush() is basically used when we write to files. Before closing the file we flush all the data.
[ SCJP 6.0 - 90% ] , JSP, Servlets and Learning EJB.
Try out the programs using a TextEditor. Textpad - Java 6 api
I hope the previous posters aren't waiting for an answer (), but I am sure you are correct. In most cases of output streams and writers, closing the object flushes the stream too. If you look at the documentation, in this case, you will find, unfortunately, that it doesn't say anything about flushing the stream.
It's cheap insurance. I'm pretty sure that most close() methods do invoke flush(), but check the docs for the class in question - and its superclasses. And when in doubt, flush anyway. Double-flushing does no harm.
I once worked with someone who thought that it was OK not to close files because the garbage collector would close them. In actuality (Java 1.4), resources would leak and buffers wouldn't flush. So I've been prone to force the matter myself.
"privilege" comes from the Latin words for "private" and "law" (legal) and dates to feudal times. To "claim privilege" meant that you were above the laws that applied to the common people.
Alas, poor Yorick, he knew this tiny ad:
Two software engineers solve most of the world's problems in one K&R sized book