BufferedStream.Close 方法

定義

關閉資料流並釋放與目前緩衝資料流建立關聯的任何資源 (特別是通訊端和檔案控制代碼等系統資源)。

public:
 override void Close();
public override void Close ();
override this.Close : unit -> unit
Public Overrides Sub Close ()

例外狀況

嘗試關閉資料流時發生錯誤。

範例

此程式代碼範例是提供給 類別之較大範例的 BufferedStream 一部分。

' When bufStream is closed, netStream is in turn 
' closed, which in turn shuts down the connection 
' and closes clientSocket.
Console.WriteLine(vbCrLf & "Shutting down the connection.")
bufStream.Close()
// When bufStream is closed, netStream is in turn
// closed, which in turn shuts down the connection
// and closes clientSocket.
Console.WriteLine("\nShutting down the connection.");
bufStream.Close();
// When bufStream is closed, netStream is in turn closed,
// which in turn shuts down the connection and closes
// clientSocket.
Console::WriteLine( "\nShutting down connection." );
bufStream->Close();

備註

先前寫入緩衝區的任何數據都會在緩衝數據流關閉之前複製到基礎數據源或存放庫。 因此,叫用 Close 之前不需要呼叫 Flush() 。 在呼叫 Close 之後,緩衝數據流上的任何作業可能會引發例外狀況。

除非您明確呼叫 Flush() 或 Close,否則清除數據流將不會排清其基礎編碼器。 設定 AutoFlush 為 true 表示數據會從緩衝區排清到數據流,但不會排清編碼器狀態。 這可讓編碼器保持其狀態 (部分字元) ,以便正確地編碼下一個字元區塊。 此案例會影響UTF8和UTF7,其中某些字元只能在編碼器收到相鄰字元或字元之後進行編碼。

試著在關閉資料串流之後操作資料流可能會擲回 ObjectDisposedException

適用於

另請參閱