Export (0) Print
Expand All

BinaryReader.Read Method (Byte[], Int32, Int32)

Reads the specified number of bytes from the stream, starting from a specified point in the byte array.

Namespace:  System.IO
Assemblies:   System.IO (in System.IO.dll)
  mscorlib (in mscorlib.dll)

abstract Read : 
        buffer:byte[] * 
        index:int * 
        count:int -> int  
override Read : 
        buffer:byte[] * 
        index:int * 
        count:int -> int

Parameters

buffer
Type: System.Byte[]

The buffer to read data into.

index
Type: System.Int32

The starting point in the buffer at which to begin reading into the buffer.

count
Type: System.Int32

The number of bytes to read.

Return Value

Type: System.Int32
The number of bytes read into buffer. This might be less than the number of bytes requested if that many bytes are not available, or it might be zero if the end of the stream is reached.

ExceptionCondition
ArgumentException

The buffer length minus index is less than count.

-or-

The number of decoded characters to read is greater than count. This can happen if a Unicode decoder returns fallback characters or a surrogate pair.

ArgumentNullException

buffer is a null reference (Nothing in Visual Basic).

ArgumentOutOfRangeException

index or count is negative.

ObjectDisposedException

The stream is closed.

IOException

An I/O error occurs.

BinaryReader does not restore the file position after an unsuccessful read operation.

For a list of common I/O tasks, see Common I/O Tasks.

The following example shows how to write binary data by using memory as a backing store. It displays a message to the console that indicates whether the data was written correctly.

No code example is currently available or this language may not be supported.

This example reads the contents of a file and displays each byte's numeric value in 16-column format. The end of the file that is being read is detected when the Read method returns zero bytes.

No code example is currently available or this language may not be supported.

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Portable Class Library

Supported in: Portable Class Library

.NET for Windows Store apps

Supported in: Windows 8

Supported in: Windows Phone 8.1

Supported in: Windows Phone Silverlight 8.1

Supported in: Windows Phone Silverlight 8

Windows Phone 8.1, Windows Phone 8, Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Show:
© 2014 Microsoft