現在のリーダーと基になるストリームをクローズします。
Public Overridable Sub Close()
[C#]
public virtual void Close();
[C++]
public: virtual void Close();
[JScript]
public function Close();
解説
この Close の実装は、 true 値を渡す Dispose メソッドを呼び出します。
ストリームをフラッシュしても、 Flush または Close を明示的に呼び出さない限り、そのストリームの基になるエンコーダはフラッシュされません。 AutoFlush を true に設定すると、データがバッファからストリームにフラッシュされますが、エンコーダの状態はフラッシュされません。これにより、エンコーダの状態 (一部の文字) を維持できるため、次のブロックの文字を正確にエンコードできるようになります。この動作は、一部の文字をエンコードするためにはエンコーダがあらかじめその文字に隣接する文字を受け取っておく必要がある UTF8 および UTF7 に対して有効です。
使用例
[Visual Basic, C#, C++] 次のコード例は BinaryReader クラスの例の一部です。
Dim binReader As New BinaryReader( _
File.Open(fileName, FileMode.Open))
Try
' If the file is not empty,
' read the application settings.
If binReader.PeekChar() <> -1 Then
aspRatio = binReader.ReadSingle()
lkupDir = binReader.ReadString()
saveTime = binReader.ReadInt32()
statusBar = binReader.ReadBoolean()
Return
End If
' If the end of the stream is reached before reading
' the four data values, ignore the error and use the
' default settings for the remaining values.
Catch ex As EndOfStreamException
Console.WriteLine("{0} caught and ignored. " & _
"Using default values.", ex.GetType().Name)
Finally
binReader.Close()
End Try
[C#]
BinaryReader binReader =
new BinaryReader(File.Open(fileName, FileMode.Open));
try
{
// If the file is not empty,
// read the application settings.
if(binReader.PeekChar() != -1)
{
aspectRatio = binReader.ReadSingle();
lookupDir = binReader.ReadString();
autoSaveTime = binReader.ReadInt32();
showStatusBar = binReader.ReadBoolean();
}
}
// If the end of the stream is reached before reading
// the four data values, ignore the error and use the
// default settings for the remaining values.
catch(EndOfStreamException e)
{
Console.WriteLine("{0} caught and ignored. " +
"Using default values.", e.GetType().Name);
}
finally
{
binReader.Close();
}
[C++]
BinaryReader* binReader =
new BinaryReader(File::Open(fileName, FileMode::Open));
try
{
// If the file is not empty,
// read the application settings.
if(binReader->PeekChar() != -1)
{
aspectRatio = binReader->ReadSingle();
lookupDir = binReader->ReadString();
autoSaveTime = binReader->ReadInt32();
showStatusBar = binReader->ReadBoolean();
return;
}
}
// If the end of the stream is reached before reading
// the four data values, ignore the error and use the
// default settings for the remaining values.
catch(EndOfStreamException* e)
{
Console::WriteLine(S"{0} caught and ignored. "
S"Using default values.", e->GetType()->Name);
}
__finally
{
binReader->Close();
}
[JScript] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン をクリックします。
必要条件
プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ, .NET Compact Framework - Windows CE .NET
参照
BinaryReader クラス | BinaryReader メンバ | System.IO 名前空間 | 入出力操作 | ファイルからのテキストの読み取り | ファイルへのテキストの書き込み