1/28
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced | Call with Kai | Chat |
|---|
No analytics yet
Send a link to your students to track their progress
BinaryReader
A class in System.IO that reads primitive data types and strings from an underlying stream in binary form. Domain: C# → .NET → System.IO → Binary I/O
BinaryWriter
A class in System.IO that writes primitive data types and strings to an underlying stream in binary form.
Binary I/O
Reading or writing data according to its binary representation rather than treating the underlying bytes as ordinary lines of text.
new BinaryReader(stream)
Creates a BinaryReader that reads binary data from the specified Stream.
new BinaryReader(stream, encoding)
Creates a BinaryReader using a specified character encoding when decoding strings and characters contained in the binary data.
new BinaryWriter(stream)
Creates a BinaryWriter that writes binary data to the specified Stream.
new BinaryWriter(stream, encoding)
Creates a BinaryWriter using a specified character encoding when encoding strings and characters.
reader.ReadBoolean()
Reads a Boolean value from the current stream.
reader.ReadByte()
Reads the next byte from the current stream.
reader.ReadInt16()
Reads a 2-byte signed integer from the current stream.
reader.ReadInt32()
Reads a 4-byte signed integer from the current stream.
reader.ReadInt64()
Reads an 8-byte signed integer from the current stream.
reader.ReadSingle()
Reads a 4-byte single-precision floating-point value from the current stream.
reader.ReadDouble()
Reads an 8-byte double-precision floating-point value from the current stream.
reader.ReadDecimal()
Reads a Decimal value from the current stream.
reader.ReadChar()
Reads the next character from the current stream according to the reader's character encoding.
reader.ReadString()
Reads a length-prefixed string from the current stream using the reader's character encoding.
reader.BaseStream
Gets the underlying Stream used by the BinaryReader.
writer.Write(value)
Writes a value to the underlying stream in the binary representation associated with the value's type.
writer.Flush()
Clears BinaryWriter's buffers by writing buffered data to the underlying stream.
writer.BaseStream
Gets the underlying Stream used by the BinaryWriter.
Binary Write/Read Order
Binary values must generally be read according to the same format, type sequence, and order in which they were written.
BinaryWriter String Format
BinaryWriter.Write(string) writes an encoded string preceded by length information that BinaryReader.ReadString() uses when reading it back.
BinaryReader End of Data
Attempting to read a required value when insufficient data remains can cause an EndOfStreamException.
BinaryReader Disposal
Disposing a BinaryReader normally disposes its underlying stream unless the reader was configured to leave the stream open.
BinaryWriter Disposal
Disposing a BinaryWriter normally disposes its underlying stream unless the writer was configured to leave the stream open.
leaveOpen
A constructor option that allows the underlying stream to remain open after a BinaryReader or BinaryWriter is disposed.
BinaryReader/BinaryWriter Pair
BinaryWriter serializes supported primitive values to a stream and BinaryReader reconstructs those values when the same binary format is followed.
Binary I/O vs Text I/O
BinaryReader and BinaryWriter operate on typed binary representations, whereas StreamReader and StreamWriter convert between encoded bytes and human-readable text.