Mono Class Library: System.IO.FileStream Overview | Members

System.IO.FileStream.Read Method

Reads a block of bytes from the stream and returns the data in the specified buffer. [Edit]

public override int Read (byte[] array, int offset, int count)

Parameters

array
A byte array. When this method returns, the bytes between offset and (offset + count - 1) in array are replaced by the bytes read from the current stream. [Edit]
offset
A int containing the byte offset in array at which to begin writing data read from the current stream. [Edit]
count
A int containing maximum number of bytes to read. [Edit]

Returns

A int containing the total number of bytes read into the buffer, or zero if the end of the stream is reached. [Edit]

Exceptions

TypeReason
ArgumentNullExceptionarray is null. [Edit]
ArgumentOutOfRangeExceptionoffset or count is negative. [Edit]
NotSupportedExceptionThe current stream does not support reading. [Edit]
System.IO.IOExceptionAn I/O error occurred. [Edit]
ArgumentExceptionoffset + count is greater than the length of array. [Edit]
ObjectDisposedExceptionThe current stream is closed. [Edit]

Remarks

The FileStream.Read(Byte[], int, int) method returns zero only after reaching the end of the stream. Otherwise, FileStream.Read(Byte[], int, int) always reads at least one byte from the stream before returning. If no data is available from the stream, this method blocks until at least one byte of data can be returned.

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.

Note: Use the FileStream.CanRead property to determine whether the current instance supports reading. For additional information, see Stream.CanRead.

Note: This method overrides Stream.Read(Byte[], int, int) .

[Edit]

Requirements

Namespace: System.IO
Assembly: mscorlib (in mscorlib.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0