C# 中 BinaryWriter 类用于向流中写入内容,其构造方法与上一节《C# BinaryReader》中介绍的 BinaryReader 类中的类似,具体的语法形式如下。
第1种形式:
BinaryWriter(Stream output)
第2种形式:
BinaryWriter(Stream output, Encoding encoding)
第3种形式:
BinaryWriter(Stream output, Encoding encoding, bool leaveOpen)
BinaryWriter 类中常用的属性和方法如下表所示。
属性或方法 | 作用 |
---|---|
void Close() | 关闭流 |
void Flush() | 清理当前编写器的所有缓冲区,使所有缓冲数据写入基础设备 |
long Seek(int offset, SeekOrigin origin) | 返回查找的当前流的位置 |
void Write(char[] chars) | 将字符数组写入当前流 |
Write7BitEncodedInt(in |