Namespace: System.IO
BinaryReader
Reads primitive data types as binary values in a specific encoding.
Properties (1)
Stream BaseStream
Exposes access to the underlying stream of the BinaryReader.
Value: The underlying stream associated with the BinaryReader.
Methods (14)
BinaryReader(IO.Stream,Text.Encoding,Boolean)Constructor
Initializes a new instance of the BinaryReader class based on the specified stream and character encoding, and optionally leaves the stream open.
| Parameter | Description |
|---|---|
| input | The input stream. |
| encoding | The character encoding to use. |
| leaveOpen | true to leave the stream open after the BinaryReader object is disposed; otherwise, false. |
BinaryReader(IO.Stream)Constructor
Initializes a new instance of the BinaryReader class based on the specified stream and using UTF-8 encoding.
| Parameter | Description |
|---|---|
| input | The input stream. |
bool ReadBoolean
Reads a Boolean value from the current stream and advances the current position of the stream by one byte.
Returns: true if the byte is nonzero; otherwise, false.
byte ReadByte
Reads the next byte from the current stream and advances the current position of the stream by one byte.
Returns: The next byte read from the current stream.
short ReadInt16
Reads a 2-byte signed integer from the current stream and advances the current position of the stream by two bytes.
Returns: A 2-byte signed integer read from the current stream.
ushort ReadUInt16
Reads a 2-byte unsigned integer from the current stream using little-endian encoding and advances the position of the stream by two bytes.
Returns: A 2-byte unsigned integer read from this stream.
int ReadInt32
Reads a 4-byte signed integer from the current stream and advances the current position of the stream by four bytes.
Returns: A 4-byte signed integer read from the current stream.
uint ReadUInt32
Reads a 4-byte unsigned integer from the current stream and advances the position of the stream by four bytes.
Returns: A 4-byte unsigned integer read from this stream.
long ReadInt64
Reads an 8-byte signed integer from the current stream and advances the current position of the stream by eight bytes.
Returns: An 8-byte signed integer read from the current stream.
ulong ReadUInt64
Reads an 8-byte unsigned integer from the current stream and advances the position of the stream by eight bytes.
Returns: An 8-byte unsigned integer read from this stream.
float ReadSingle
Reads a 4-byte floating point value from the current stream and advances the current position of the stream by four bytes.
Returns: A 4-byte floating point value read from the current stream.
double ReadDouble
Reads an 8-byte floating point value from the current stream and advances the current position of the stream by eight bytes.
Returns: An 8-byte floating point value read from the current stream.
String ReadString
Reads a string from the current stream. The string is prefixed with the length, encoded as an integer seven bits at a time.
Returns: The string being read.
void Close
Closes the current reader and the underlying stream.