Namespace: System.IO
BinaryWriter
Writes primitive types in binary to a stream and supports writing strings in a specific encoding.
Properties (1)
Stream BaseStream
Gets the underlying stream of the BinaryWriter.
Value: The underlying stream associated with the BinaryWriter.
Methods (14)
BinaryWriter(IO.Stream,Text.Encoding,Boolean)Constructor
Initializes a new instance of the BinaryWriter class based on the specified stream and character encoding, and optionally leaves the stream open.
| Parameter | Description |
|---|---|
| output | The output stream. |
| encoding | The character encoding to use. |
| leaveOpen | true to leave the stream open after the BinaryWriter object is disposed; otherwise, false. |
BinaryWriter(IO.Stream)Constructor
Initializes a new instance of the BinaryWriter class based on the specified stream and using UTF-8 encoding.
| Parameter | Description |
|---|---|
| output | The output stream. |
void Write(Boolean)
Writes a one-byte Boolean value to the current stream, with 0 representing false and 1 representing true.
| Parameter | Description |
|---|---|
| value | The Boolean value to write (0 or 1). |
void Write(Byte)
Writes an unsigned byte to the current stream and advances the stream position by one byte.
| Parameter | Description |
|---|---|
| value | The unsigned byte to write. |
void Write(Int16)
Writes a two-byte signed integer to the current stream and advances the stream position by two bytes.
| Parameter | Description |
|---|---|
| value | The two-byte signed integer to write. |
void Write(UInt16)
Writes a two-byte unsigned integer to the current stream and advances the stream position by two bytes.
| Parameter | Description |
|---|---|
| value | The two-byte unsigned integer to write. |
void Write(Int32)
Writes a four-byte signed integer to the current stream and advances the stream position by four bytes.
| Parameter | Description |
|---|---|
| value | The four-byte signed integer to write. |
void Write(UInt32)
Writes a four-byte unsigned integer to the current stream and advances the stream position by four bytes.
| Parameter | Description |
|---|---|
| value | The four-byte unsigned integer to write. |
void Write(Int64)
Writes an eight-byte signed integer to the current stream and advances the stream position by eight bytes.
| Parameter | Description |
|---|---|
| value | The eight-byte signed integer to write. |
void Write(UInt64)
Writes an eight-byte unsigned integer to the current stream and advances the stream position by eight bytes.
| Parameter | Description |
|---|---|
| value | The eight-byte unsigned integer to write. |
void Write(Single)
Writes a four-byte floating-point value to the current stream and advances the stream position by four bytes.
| Parameter | Description |
|---|---|
| value | The four-byte floating-point value to write. |
void Write(Double)
Writes an eight-byte floating-point value to the current stream and advances the stream position by eight bytes.
| Parameter | Description |
|---|---|
| value | The eight-byte floating-point value to write. |
void Write(String)
Writes a length-prefixed string to this stream in the current encoding of the BinaryWriter, and advances the current position of the stream in accordance with the encoding used and the specific characters being written to the stream.
| Parameter | Description |
|---|---|
| value | The value to write. |
void Close
Closes the current BinaryWriter and the underlying stream.