次の方法で共有


StreamReader.Null フィールド

空のストリームの StreamReader

Public Shared ReadOnly Null As StreamReader
[C#]
public static readonly StreamReader Null;
[C++]
public: static StreamReader* Null;
[JScript]
public static var Null : StreamReader;

解説

StreamReader.Null に対して読み込みメソッドを呼び出すと、常に 0 が返されます。 StreamReader.Null に対して ReadLine を呼び出すと、 null 参照 (Visual Basic では Nothing) が返されます。

このフィールドの使用方法の例については、下の例を参照してください。その他の一般的な I/O タスクまたは関連する I/O タスクの例を次の表に示します。

実行するタスク 参考例があるトピック
テキスト ファイルを作成する。 ファイルへのテキストの書き込み
テキスト ファイルに書き込む。 ファイルへのテキストの書き込み
テキスト ファイルから読み取る。 ファイルからのテキストの読み取り
テキストをファイルに追加する。 ログ ファイルのオープンと追加

File.AppendText

FileInfo.AppendText

ファイルのサイズを取得する。 FileInfo.Length
ファイルの属性を取得する。 File.GetAttributes
ファイルの属性を設定する。 File.SetAttributes
ファイルが存在するかどうかを判別する。 File.Exists
バイナリ ファイルから読み取る。 新しく作成したデータ ファイルの読み取りと書き込み
バイナリ ファイルに書き込む。 新しく作成したデータ ファイルの読み取りと書き込み

使用例

[Visual Basic, C#, C++] Null フィールドの例を次に示します。

 
Dim SNull As Stream
SNull = File.OpenRead("C:\Temp\Test.txt")
Dim SrNull As StreamReader = New StreamReader(SNull, _
    System.Text.Encoding.ASCII)
If (SrNull.Equals(StreamReader.Null) <> True) Then
    SrNull.BaseStream.Seek(0, SeekOrigin.Begin)
    Console.WriteLine(SrNull.ReadToEnd())
End If
SrNull.Close()

[C#] 
StreamReader srNull = new StreamReader(
    (System.IO.Stream)File.OpenRead("C:\\Temp\\Test.txt"),
    System.Text.Encoding.ASCII);
if(!srNull.Equals(StreamReader.Null)) 
{
    srNull.BaseStream.Seek(0, SeekOrigin.Begin);
    Console.WriteLine(srNull.ReadToEnd());
}
srNull.Close();

[C++] 
StreamReader *srNull = new StreamReader(
    File::OpenRead("C:\\Temp\\Test.txt"),
    System::Text::Encoding::ASCII);
if(!srNull->Equals(StreamReader::Null)) {
    srNull->BaseStream->Seek(0, SeekOrigin::Begin);
    Console::WriteLine(srNull->ReadToEnd());
}
srNull->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

参照

StreamReader クラス | StreamReader メンバ | System.IO 名前空間 | 入出力操作 | ファイルからのテキストの読み取り | ファイルへのテキストの書き込み