TextReader.Read メソッド
定義
テキスト リーダーからデータを読み取ります。Reads data from the text reader.
オーバーロード
Read() |
テキスト リーダーから次の文字を読み取り、1 文字分だけ文字位置を進めます。Reads the next character from the text reader and advances the character position by one character. |
Read(Span<Char>) |
現在のリーダーから文字を読み取り、指定したバッファーにそのデータを書き込みます。Reads the characters from the current reader and writes the data to the specified buffer. |
Read(Char[], Int32, Int32) |
指定した最大文字数を現在のリーダーから読み取り、バッファーの指定したインデックス位置にそのデータを書き込みます。Reads a specified maximum number of characters from the current reader and writes the data to a buffer, beginning at the specified index. |
Read()
テキスト リーダーから次の文字を読み取り、1 文字分だけ文字位置を進めます。Reads the next character from the text reader and advances the character position by one character.
public:
virtual int Read();
public virtual int Read ();
abstract member Read : unit -> int
override this.Read : unit -> int
Public Overridable Function Read () As Integer
戻り値
テキスト リーダーからの次の文字。それ以上読み取り可能な文字がない場合は -1。The next character from the text reader, or -1 if no more characters are available. 既定の実装では、-1 が返されます。The default implementation returns -1.
例外
TextReader が閉じています。The TextReader is closed.
I/O エラーが発生します。An I/O error occurs.
注釈
TextReader クラスは抽象クラスです。The TextReader class is an abstract class. そのため、コードでそれをインスタンス化することはありません。Therefore, you do not instantiate it in your code. メソッドの使用例については、 Read メソッドを参照してください StreamReader.Read 。For an example of using the Read method, see the StreamReader.Read method.
こちらもご覧ください
- Read()
- Read()
- ファイルおよびストリーム入出力File and Stream I/O
- 方法:ファイルからのテキストの読み取りHow to: Read Text from a File
- 方法:ファイルにテキストを書き込むHow to: Write Text to a File
適用対象
Read(Span<Char>)
現在のリーダーから文字を読み取り、指定したバッファーにそのデータを書き込みます。Reads the characters from the current reader and writes the data to the specified buffer.
public:
virtual int Read(Span<char> buffer);
public virtual int Read (Span<char> buffer);
abstract member Read : Span<char> -> int
override this.Read : Span<char> -> int
Public Overridable Function Read (buffer As Span(Of Char)) As Integer
パラメーター
このメソッドから制御が戻るときに、指定した文字のスパンが現在のソースから読み取られた文字に置き換えられます。When this method returns, contains the specified span of characters replaced by the characters read from the current source.
戻り値
読み取られた文字数。The number of characters that have been read. この数値は、リーダー内に使用できるデータがあるかどうかに応じて、buffer
の長さより小さいか等しくなります。The number will be less than or equal to the buffer
length, depending on whether the data is available within the reader. 読み取り対象の文字がない場合にこのメソッドを呼び出すと、0 (ゼロ) が返されます。This method returns 0 (zero) if it is called when no more characters are left to read.
例外
buffer
が null
です。buffer
is null
.
ストリームから読み取った文字数が、buffer
の長さを超えています。The number of characters read from the stream is larger than the length of the buffer
.
適用対象
Read(Char[], Int32, Int32)
指定した最大文字数を現在のリーダーから読み取り、バッファーの指定したインデックス位置にそのデータを書き込みます。Reads a specified maximum number of characters from the current reader and writes the data to a buffer, beginning at the specified index.
public:
virtual int Read(cli::array <char> ^ buffer, int index, int count);
public virtual int Read (char[] buffer, int index, int count);
abstract member Read : char[] * int * int -> int
override this.Read : char[] * int * int -> int
Public Overridable Function Read (buffer As Char(), index As Integer, count As Integer) As Integer
パラメーター
- buffer
- Char[]
このメソッドが戻るとき、指定した文字配列の index
から (index
+ count
- 1) までの値が、現在のソースから読み取られた文字に置き換えられます。When this method returns, contains the specified character array with the values between index
and (index
+ count
- 1) replaced by the characters read from the current source.
- index
- Int32
書き込みを開始する buffer
内の位置。The position in buffer
at which to begin writing.
- count
- Int32
読み取り対象の最大文字数。The maximum number of characters to read. 指定された文字数をバッファーに読み取る前にリーダーの末尾に到達した場合、メソッドは制御を返します。If the end of the reader is reached before the specified number of characters is read into the buffer, the method returns.
戻り値
読み取られた文字数。The number of characters that have been read. この数値は、リーダー内に使用できるデータがあるかどうかによって異なりますが、count
以下の数値になります。The number will be less than or equal to count
, depending on whether the data is available within the reader. 読み取り対象の文字がない場合にこのメソッドを呼び出すと、0 (ゼロ) が返されます。This method returns 0 (zero) if it is called when no more characters are left to read.
例外
buffer
が null
です。buffer
is null
.
バッファーの長さから index
を引いた値が count
未満です。The buffer length minus index
is less than count
.
index
または count
が負の値です。index
or count
is negative.
TextReader が閉じています。The TextReader is closed.
I/O エラーが発生します。An I/O error occurs.
注釈
このメソッドは、いずれかの count
文字が読み取られた後、またはファイルの末尾に到達した後に戻ります。This method returns after either count
characters are read or the end of the file is reached. ReadBlock は、このメソッドのブロッキングバージョンです。ReadBlock is a blocking version of this method.
TextReader クラスは抽象クラスです。The TextReader class is an abstract class. そのため、コードでそれをインスタンス化することはありません。Therefore, you do not instantiate it in your code. メソッドの使用例については、 Read メソッドを参照してください StreamReader.Read 。For an example of using the Read method, see the StreamReader.Read method.
こちらもご覧ください
- Read(Char[], Int32, Int32)
- Read(Char[], Int32, Int32)
- ファイルおよびストリーム入出力File and Stream I/O
- 方法:ファイルからのテキストの読み取りHow to: Read Text from a File
- 方法:ファイルにテキストを書き込むHow to: Write Text to a File