File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Flushing IO streams............." Watch "Flushing IO streams............." New topic
Author

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]http://javacollectionsnotes.blogspot.com[/url] | [url]http://omkar-myscjpexp.blogspot.com[/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.

Layne


Java API Documentation
The Java Tutorial
 
 
subject: Flushing IO streams.............