Venkat Venkat - 9 months ago 51
Java Question

What is the purpose of flush() in Java streams?

In Java,

method is used in streams. But I don't understand what are all the purpose of using this method?


tell me some suggestions.


From the docs of the flush method:

Flushes the output stream and forces any buffered output bytes to be written out. The general contract of flush is that calling it is an indication that, if any bytes previously written have been buffered by the implementation of the output stream, such bytes should immediately be written to their intended destination.

The buffering is mainly done to improve the I/O performance. More on this can be read from this article: Tuning Java I/O Performance.