Reads a block of bytes from the stream and writes the data in a given buffer.
[Visual Basic] Overrides Public Function Read( _ ByVal array() As Byte, _ ByVal offset As Integer, _ ByVal count As Integer _ ) As Integer [C#] public override int Read( byte[] array, int offset, int count ); [C++] public: override int Read( unsigned char* array[], int offset, int count ); [JScript] public override function Read( array : Byte[], offset : int, count : int ) : int;
The total number of bytes read into the buffer. This may be less than the number of bytes requested if that many bytes aren't currently available, or zero if the end of the stream is reached.
Exception Type | Condition |
---|---|
ArgumentNullException | array is null. |
ArgumentOutOfRangeException | offset or count is less than zero. |
NotSupportedException | The stream does not support reading. |
IOException | An I/O error occurs. |
ArgumentException | offset and count describe an invalid range in array. |
The offset parameter gives the offset of the byte in array at which to begin writing (index in the buffer), and the count parameter gives the maximum number of bytes that will be read from this stream. The returned value is the actual number of bytes read, or zero if the end of the stream is reached. If the read operation is successful, the current position of the stream is advanced by the number of bytes read. If an exception occurs, the current position of the stream is unchanged.
The Read method will return zero only if the end of the stream is reached. In all other cases, Read always reads at least one byte from the stream before returning. If no data is available from the stream upon a call to Read, the method will block until at least one byte of data can be returned.