Stream.Flush 方法

定義

當在衍生類別中覆寫時,會清除這個資料流的所有緩衝區,並造成所有緩衝資料都寫入基礎裝置。When overridden in a derived class, clears all buffers for this stream and causes any buffered data to be written to the underlying device.

public:
 abstract void Flush();
public abstract void Flush ();
abstract member Flush : unit -> unit
Public MustOverride Sub Flush ()

例外狀況

發生 I/O 錯誤。An I/O error occurs.

備註

Flush執行緩衝區的資料流程上覆寫。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). 如需詳細資訊,請參閱 CanSeekFor additional information see CanSeek.

在衍生自Stream但不支援寫入的類別中Flush ,通常會實作為空的方法,以確保與其他Stream類型完全相容,因為它是有效的,可排清唯讀資料流程。In a class derived from Stream that doesn't support writing, Flush is typically implemented as an empty method to ensure full compatibility with other Stream types since it's valid to flush a read-only stream.

使用StreamWriter StreamBinaryWriter類別時,請勿清除基底物件。When using the StreamWriter or BinaryWriter class, do not flush the base Stream object. 相反地,請使用類別FlushClose或方法,這會先將資料排清到基礎資料流程,然後再寫入檔案中。Instead, use the class's Flush or Close method, which makes sure that the data is flushed to the underlying stream first and then written to the file.

適用於

另請參閱