These are stream helper classes that make it easier to read and write data in specific formats onto an underlying stream. The following table describes the BinaryReader class’s most useful methods.
Method | Purpose |
---|---|
Close | Closes the BinaryReader and its underlying stream. |
PeekChar | Reads the reader’s next character, but does not advance the reader’s position, so other methods can still read the character later. |
Read | Reads characters from the stream and advances the reader’s position. |
ReadBoolean | Reads a Boolean from the stream and advances the reader’s position by 1 byte. |
ReadByte | Reads a byte from the stream and advances the reader’s position by 1 byte. |
ReadBytes | Reads a number of bytes from the stream into a byte array and advances the reader’s position by that number of bytes. |
ReadChar | Reads a character from the stream and advances the reader’s position according to the stream’s encoding and the character. |
ReadChars | Reads a number of characters from the stream, returns the results in a character array, and advances the reader’s position according to the stream’s encoding and the number of characters. |
ReadDecimal | Reads a decimal value from the stream and advances the reader’s position by 16 bytes. |
ReadDouble | Reads an 8-byte floating-point value from the stream and advances the reader’s position by 8 bytes. |
ReadInt16 | Reads a 2-byte signed integer from the stream and advances the reader’s position by 2 bytes. |
ReadInt32 | Reads a 4-byte signed integer from the stream and advances the reader’s position by 4 bytes. |
ReadInt64 | Reads an 8-byte signed integer from the stream and advances the reader’s position by 8 bytes. |
ReadSByte | Reads a signed byte from the stream and advances the reader’s position by 1 byte. |
ReadSingle | Reads a 4-byte floating-point value from the stream and advances the reader’s position by 4 bytes. |
ReadString | Reads a string from the current stream and advances the reader’s position past it. The string begins with its length. |
ReadUInt16 | Reads a 2-byte unsigned integer from the stream and advances the reader’s position by 2 bytes. |
ReadUInt32 | Reads a 4-byte unsigned integer from the stream and advances the reader’s position by 4 bytes. |
ReadUInt64 | Reads an 8-byte unsigned integer from the stream and advances the reader’s position by 8 bytes. |
The following table describes the BinaryWriter class’s most useful methods.
Name | Description |
---|---|
Close | Closes the BinaryWriter and its underlying stream. |
Flush | Writes any buffered data into the underlying stream. |
Seek | Sets the position within the stream. |
Write | Writes a value into the stream. This method has many overloaded versions that write characters, arrays of characters, integers, strings, unsigned 64-bit integers, and so on. |