共用方式為


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處置設為 true 以釋放其資源,然後呼叫 SuppressFinalize 以隱藏垃圾收集行程對此對象的最終處理。

適用於