flush() method is used to force the data in the buffer to be written to the underlying target. Can be used for OutputStream, Writer and Flushable objects, the usage is as follows: OutputStream: outputStream.flush()Writer: writer.flush()Flushable: flushable.flush()
#The meaning of flush() method in Java
#flush() method is a method used to force the data in the buffer to be written to the underlying target, usually used for stream objects middle.
How to use flush() method?
The flush() method is available on the following stream objects:
The usage method is very simple, just call the flush() method on the stream object, as shown below:
<code class="java">OutputStream outputStream = ...; outputStream.flush(); Writer writer = ...; writer.flush(); Flushable flushable = ...; flushable.flush();</code>
flush() method Effect
flush() method will force all data in the buffer to be written to the underlying destination, even if the buffer is not full. This is useful when:
The difference between the close() method
The flush() method is different from the close() method. The close() method will close the stream and release all systems resource, and the flush() method will only force the data in the buffer to be written and will not close the stream.
The above is the detailed content of What does flush mean in java. For more information, please follow other related articles on the PHP Chinese website!