When do we need to flush an output stream?The stream data available in the buffer needs to be flushed out, when new data is to be written to that buffer. The flushed out stream outputs the bytes to another output stream. The contract of flush() method is to be flushed / written to their intended destination output stream immediately.When do we need to flush an output stream?If any bytes that are previously written and have been buffered by the implementation of the output stream then such bytes need to be immediately written to their intended destination. This is where flush needs to be used. It flushes this output stream and forces any buffered output bytes to be written out.
The use of flush() comes when any bytes previously written have been buffered by the implementation of the output stream. Such bytes should be immediately written to their expected destination.
|