IsolatedStorageFileStream.Close 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
釋放與 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 以隱藏垃圾收集行程對此對象的最終處理。
適用於
意見反應
https://aka.ms/ContentUserFeedback。
即將登場:在 2024 年,我們將逐步淘汰 GitHub 問題作為內容的意見反應機制,並將它取代為新的意見反應系統。 如需詳細資訊,請參閱:提交並檢視相關的意見反應