次の方法で共有


IsolatedStorageFileStream.Close メソッド

IsolatedStorageFileStream に関連付けられているリソースを解放します。

Overrides Public Sub Close()
[C#]
public override void Close();
[C++]
public: void Close();
[JScript]
public override function Close();

解説

以前にバッファに書き込まれたデータは、ファイル ストリームが閉じられる前に、ファイルにコピーされます。したがって、 Close を呼び出す前に Flush を呼び出す必要はありません。

Close を呼び出した後に、そのファイル ストリームを操作しようとすると例外が発生することがあります。 Close を 1 回呼び出した後に、再び呼び出しても何も実行されません。 Finalize メソッドは、 Close を呼び出して、ガベージ コレクタがオブジェクトを終了する前にファイル ストリームを閉じます。

IsolatedStorageFileStream オブジェクトは、アクセスするファイルのストレージ コンテキストを決定する IsolatedStorageFile を要求します。 IsolatedStorageFile オブジェクトを渡さずに開かれたストリームでは、既定の IsolatedStorageFile は実行中のアセンブリ用に作成され、 Close の呼び出し中に閉じられます。

メモ    Close メソッドは、 disposingtrue に設定して Dispose を呼び出すことでストリームのリソースを解放した後で、このオブジェクトがガベージ コレクタによって完全に終了されることがないように、 SuppressFinalize を呼び出します。

使用例

[Visual Basic, C#] 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();
[Visual Basic] 
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()

[C++, JScript] C++ および JScript のサンプルはありません。Visual Basic および C# のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン 言語のフィルタ をクリックします。

必要条件

プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ

参照

IsolatedStorageFileStream クラス | IsolatedStorageFileStream メンバ | System.IO.IsolatedStorage 名前空間