c# binarywriter
类用于将二进制信息写入流中。它在system.io
命名空间中找到。它还支持以特定编码编写字符串。
我们来看看将数据写入数据文件的binarywriter
类的简单例子。
using system;
using system.io;
namespace binarywriterexample
{
class program
{
static void main(string[] args)
{
string filename = "e:\\binaryfile.dat";
using (binarywriter writer = new binarywriter(file.open(filename, filemode.create)))
{
writer.write(1024);
writer.write("this is string data");
writer.write(true);
}
console.writeline("data written successfully...");
}
}
}
执行上面示例代码,得到以下结果 -
data written successfully...