現在のストリームから Boolean 値を読み取り、ストリームの現在位置を 1 バイトだけ進めます。
Public Overridable Function ReadBoolean() As Boolean
[C#]
public virtual bool ReadBoolean();
[C++]
public: virtual bool ReadBoolean();
[JScript]
public function ReadBoolean() : Boolean;
戻り値
読み取ったバイトが 0 以外の場合は true 。0 の場合は false 。
例外
例外の種類 | 条件 |
---|---|
EndOfStreamException | ストリームの末尾に到達しました。 |
ObjectDisposedException | ストリームが閉じられました。 |
IOException | I/O エラーが発生しました。 |
解説
その他の一般的な I/O タスクまたは関連する I/O タスクの例を次の表に示します。
実行するタスク | 参考例があるトピック |
---|---|
テキスト ファイルを作成する。 | ファイルへのテキストの書き込み |
テキスト ファイルに書き込む。 | ファイルへのテキストの書き込み |
テキスト ファイルから読み取る。 | ファイルからのテキストの読み取り |
テキストをファイルに追加する。 | ログ ファイルのオープンと追加 |
ファイルのサイズを取得する。 | FileInfo.Length |
ファイルの属性を取得する。 | File.GetAttributes |
ファイルの属性を設定する。 | File.SetAttributes |
ファイルが存在するかどうかを判別する。 | File.Exists |
バイナリ ファイルから読み取る。 | 新しく作成したデータ ファイルの読み取りと書き込み |
バイナリ ファイルに書き込む。 | 新しく作成したデータ ファイルの読み取りと書き込み |
使用例
[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 名前空間 | 入出力操作 | ファイルからのテキストの読み取り | ファイルへのテキストの書き込み