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 释放设置为 true 的方法调用 Dispose 以释放其资源,然后调用 SuppressFinalize 以禁止垃圾回收器结束此对象。

适用于