Export (0) Print
Expand All

Stream.Close Method

Closes the current stream and releases any resources (such as sockets and file handles) associated with the current stream.

[Visual Basic]
Public Overridable Sub Close()
[C#]
public virtual void Close();
[C++]
public: virtual void Close();
[JScript]
public function Close();

Remarks

Flushing the stream will not flush its underlying encoder unless you explicitly call an implementation of Flush or Close. 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. This scenario affects UTF8 and UTF7 where certain characters can only be encoded after the encoder receives the adjacent character or characters.

A call to Close is required for proper operation of a stream. Following a call to Close, other operations on the stream could throw exceptions. If the stream is already closed, a call to Close throws no exceptions.

Attempts to manipulate the stream after the stream has been closed might throw an ObjectDisposedException.

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, .NET Compact Framework, Common Language Infrastructure (CLI) Standard

See Also

Stream Class | Stream Members | System.IO Namespace | Working with I/O | Reading Text from a File | Writing Text to a File

Show:
© 2014 Microsoft