The total number of bytes read into the buffer. This might be less than the number of bytes requested if that number of bytes are not currently available, or zero if the end of the stream is reached.
Type Reason ArgumentNullException array is null. ArgumentOutOfRangeException offset or count is negative. NotSupportedException The current stream does not support reading. System.IO.IOException An I/O error occurred. ArgumentException offset + count is greater than the length of array. ObjectDisposedException The current stream is closed.
This method overrides Stream.Read(Byte[], int, int).
The offset parameter gives the offset of the byte in array (the buffer index) at which to begin reading, and the count parameter gives the maximum number of bytes to 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 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 upon a call to FileStream.Read(Byte[], int, int), the method will block until at least one byte of data can be returned. An implementation is free to return fewer bytes than requested even if the end of the stream has not been reached.
Use System.IO.BinaryReader for reading primitive data types.
Do not interrupt a thread that is performing a read operation. Although the application may appear to run successfully after the thread is unblocked, the interruption can decrease your application's performance and reliability.
For a list of common file and directory operations, see Common I/O Tasks.