Stream. Close 方法
关闭流并释放与当前缓冲流关联的所有资源（尤其是系统资源，如套接字和文件句柄）。Closes the stream and releases any resources (especially system resources such as sockets and file handles) associated with the current buffered stream.
public: override void Close();
public override void Close ();
override this.Close : unit -> unit
Public Overrides Sub Close ()
尝试关闭流时出错。An error occurred while trying to close the stream.
' 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();
缓冲流关闭之前，以前写入缓冲区的任何数据都将复制到基础数据源或存储库。Any data previously written to the buffer is copied to the underlying data source or repository before the buffered stream is closed. 因此，在调用 Close 之前，无需调用 Flush()。Therefore, it is not necessary to call Flush() before invoking Close. 调用 Close 后，缓冲流上的任何操作都可能引发异常。Following a call to Close, any operations on the buffered stream might raise exceptions.
除非显式调用 Flush() 或 Close，否则刷新流将不会刷新其基础编码器。Flushing the stream will not flush its underlying encoder unless you explicitly call Flush() or Close. 如果将 AutoFlush 设置为 true，则表示数据将从缓冲区刷新到流，但编码器状态不会被刷新。Setting AutoFlush to true means that data will be flushed from the buffer to the stream, but the encoder state will not be flushed. 这允许编码器保留其状态（部分字符），以使其能够正确编码下一个字符块。This allows the encoder to keep its state (partial characters) so that it can encode the next block of characters correctly. 此方案影响 UTF8 和 UTF7，其中某些字符只能在编码器接收到相邻字符后编码。This scenario affects UTF8 and UTF7 where certain characters can only be encoded after the encoder receives the adjacent character or characters.