指定したストリームを基にし、UTF8Encoding を使用して、BinaryReader クラスの新しいインスタンスを初期化します。
名前空間: System.IO
アセンブリ: mscorlib (mscorlib.dll 内)
構文
'宣言
Public Sub New ( _
input As Stream _
)
'使用
Dim input As Stream
Dim instance As New BinaryReader(input)
public BinaryReader (
Stream input
)
public:
BinaryReader (
Stream^ input
)
public BinaryReader (
Stream input
)
public function BinaryReader (
input : Stream
)
パラメータ
- input
ストリーム。
例外
例外の種類 | 条件 |
---|---|
ストリームが読み取りをサポートしていないか、null 参照 (Visual Basic では Nothing) であるか、または既に閉じています。 |
解説
その他の一般的な I/O タスクまたは関連する I/O タスクの例を次の表に示します。
実行するタスク |
参考例があるトピック |
---|---|
テキスト ファイルを作成する。 |
|
テキスト ファイルに書き込む。 |
|
テキスト ファイルから読み取る。 |
|
バイナリ ファイルから読み取る。 |
|
バイナリ ファイルに書き込む。 |
使用例
このコード例は、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
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();
}
BinaryReader^ binReader = gcnew 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( "{0} caught and ignored. "
"Using default values.", e->GetType()->Name );
}
finally
{
binReader->Close();
}
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().get_Name());
}
finally {
binReader.Close();
}
プラットフォーム
Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。
バージョン情報
.NET Framework
サポート対象 : 2.0、1.1、1.0
.NET Compact Framework
サポート対象 : 2.0、1.0
参照
関連項目
BinaryReader クラス
BinaryReader メンバ
System.IO 名前空間
UTF8Encoding