System.IO.FileStream.Close Method
Closes the file and releases any resources associated with the current file stream.

Syntax

public override void Close ()

Remarks

This method is equivalent to FileStream.Dispose(bool)(true).

Any data previously written to the buffer is copied to the file before the file stream is closed, so it is not necessary to call FileStream.Flush before invoking Close. Following a call to Close, any operations on the file stream might raise exceptions. Invoking this method on the same instance multiple times does not result in an exception.

Usage
The FileStream.Finalize method invokes Close so that the file stream is closed before the garbage collector finalizes the object. However, objects writing to the System.IO.FileStream, such as a System.IO.StreamWriter, might not have flushed the data from their internal buffers to the System.IO.FileStream when the call to Finalize closes the stream. To prevent data loss, always call Close on the highest-level object.

Note: This method overrides Stream.Close.

Requirements

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