This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Flushing IO streams.............

 
omkar patkar
Ranch Hand
Posts: 231
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In C/C++ prgs we could "flush" the io streams,......... is it possible in Java ?....Firstly is their any need to perform flushing explictly OR Java does it on its own and if yes then how does it do that ?
 
Layne Lund
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The OutputStream class has a flush() method that you can call to flush the stream. Notice that InputStream does not have any such method since there is no reason to flush an InputStream.

It is best to flush explicitly, but there are some cases where Java will do it for you:

1) OutputStream.close() calls OutputStream.flush() before closing the stream.

2) Java *might* flush the stream at other times. For example, if you are using a BufferedOutputStream, the stream will flush itself automatically if the buffer is filled. I guess there might be other situations where this will happen as well, but I can't think of any off the top of my head.

Layne
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic