Meaningless Drivel is fun!
The moose likes Java in General and the fly likes Flushing IO streams............. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Flushing IO streams............." Watch "Flushing IO streams............." New topic

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

omkar patkar
Ranch Hand

Joined: Aug 25, 2005
Posts: 231
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 ?

Thanks and Regards
Omkar Patkar (SCJP 1.4)[url][/url] | [url][/url]
Layne Lund
Ranch Hand

Joined: Dec 06, 2001
Posts: 3061
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.


Java API Documentation
The Java Tutorial
I agree. Here's the link:
subject: Flushing IO streams.............
It's not a secret anymore!