IsolatedStorageFileStream.Close 方法

定义

释放与 IsolatedStorageFileStream 对象关联的资源。

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

示例

下面的代码示例演示 Close 方法。

IsolatedStorageFileStream source =
     new IsolatedStorageFileStream(this.userName,FileMode.Open,isoFile);
 // This stream is the one that data will be read from
 Console.WriteLine("Source can be read?" + (source.CanRead?"true":"false"));
 IsolatedStorageFileStream target =
     new IsolatedStorageFileStream("Archive\\ " + this.userName,FileMode.OpenOrCreate,isoFile);
 // This stream is the one that data will be written to
 Console.WriteLine("Target is writable?" + (target.CanWrite?"true":"false"));
 // Do work...
 // After you have read and written to the streams, close them
 source.Close();
 target.Close();
Dim source As New IsolatedStorageFileStream(UserName,FileMode.Open,isoFile)
 ' This stream is the one that data will be read from
 If source.CanRead Then
     Console.WriteLine("Source can read ? true")
 Else
     Console.WriteLine("Source can read ? false")
 End If
 Dim target As New IsolatedStorageFileStream("Archive\\ " & UserName, _
                                             FileMode.OpenOrCreate, _
                                             isoFile)
 ' This stream is the one that data will be written to
 If target.CanWrite Then
     Console.WriteLine("Target is writable? true")
 Else
     Console.WriteLine("Target is writable? false")
 End If
 ' After you have read and written to the streams, close them
 source.Close()
 target.Close()

注解

以前写入缓冲区的任何数据在文件流关闭之前复制到文件,因此无需在调用 Close 之前调用 Flush

调用 Close 后,对文件流执行的任何操作都可能会引发异常。 调用一次后 Close ,如果再次调用,则不执行任何任务。 方法 Finalize() 调用 Close,以便在垃圾回收器完成对象之前关闭文件流。

IsolatedStorageFileStream 对象需要一个 IsolatedStorageFile 对象,该对象确定所访问文件的存储上下文。 对于在未传递 IsolatedStorageFile 对象的情况下打开的流,为正在执行的程序集创建一个默认 IsolatedStorageFile 对象,然后在调用 Close 期间关闭。

注意

方法 Close 调用 Dispose 并将 disposing 设置为 true 以释放其资源,然后调用 SuppressFinalize 以禁止垃圾回收器对此对象的最终化。

适用于