Share via


BufferedReader.Read(Char[], Int32, Int32) Method

Definition

Reads characters into a portion of an array.

[Android.Runtime.Register("read", "([CII)I", "GetRead_arrayCIIHandler")]
public override int Read (char[]? cbuf, int off, int len);
[<Android.Runtime.Register("read", "([CII)I", "GetRead_arrayCIIHandler")>]
override this.Read : char[] * int * int -> int

Parameters

cbuf
Char[]

Destination buffer

off
Int32

Offset at which to start storing characters

len
Int32

Maximum number of characters to read

Returns

The number of characters read, or -1 if the end of the stream has been reached

Attributes

Exceptions

if offset buffer.length.

if this reader is closed or some other I/O error occurs.

Remarks

Reads characters into a portion of an array.

This method implements the general contract of the corresponding {@link Reader#read(char[], int, int) read} method of the {@link Reader} class. As an additional convenience, it attempts to read as many characters as possible by repeatedly invoking the read method of the underlying stream. This iterated read continues until one of the following conditions becomes true: <ul>

<li> The specified number of characters have been read,

<li> The read method of the underlying stream returns -1, indicating end-of-file, or

<li> The ready method of the underlying stream returns false, indicating that further input requests would block.

</ul> If the first read on the underlying stream returns -1 to indicate end-of-file then this method returns -1. Otherwise this method returns the number of characters actually read.

Subclasses of this class are encouraged, but not required, to attempt to read as many characters as possible in the same fashion.

Ordinarily this method takes characters from this stream's character buffer, filling it from the underlying stream as necessary. If, however, the buffer is empty, the mark is not valid, and the requested length is at least as large as the buffer, then this method will read characters directly from the underlying stream into the given array. Thus redundant BufferedReaders will not copy data unnecessarily.

Java documentation for java.io.BufferedReader.read(char[], int, int).

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to