• Post Reply Bookmark Topic Watch Topic
  • New Topic

Serialization - flush() required after using writeObject()?  RSS feed

 
Charles Chikito
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

The following program is from Kathy and Bert's SCJP 5 Exam Study Guide book (chap 6 - Serialization)




The program compiles an runs w/o any problem.
My question is whether the os.flush(); is required?

Please advice.

Tq
 
Nitish Bangera
Ranch Hand
Posts: 537
Eclipse IDE Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Lucas Smith
Ranch Hand
Posts: 808
1
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It is a good practice in using flush() method. Just remember that readers have no flush()
 
Charles Chikito
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks to you both. I understand better now.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!