System.IO.Stream.Flush Method

When overridden in a derived class, clears all buffers for this stream and causes any buffered data to be written to the underlying device.

Syntax

public abstract void Flush ()

Exceptions

TypeReason
System.IO.IOExceptionAn I/O error occurs.
ObjectDisposedExceptionThe stream is closed.

Remarks

Override Flush on streams that implement a buffer. Use this method to move any information from an underlying buffer to its destination, clear the buffer, or both. Depending upon the state of the object, you might have to modify the current position within the stream (for example, if the underlying stream supports seeking). For additional information see Stream.CanSeek.

When using the System.IO.StreamWriter or System.IO.BinaryWriter class, do not flush the base System.IO.Stream object. Instead, use the class's Stream.Flush or Stream.Close method, which makes sure that the data is flushed to the underlying stream first and then written to the file.

Requirements

Namespace: System.IO
Assembly: mscorlib (in mscorlib.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0, 4.0.0.0