C# BinaryWriter BinaryReader demo(cctv5体育节目表)

网友投稿 720 2022-09-15

C# BinaryWriter BinaryReader demo(cctv5体育节目表)

C# BinaryWriter BinaryReader demo(cctv5体育节目表)

static void BinaryWriterReaderDemo()

{

using (FileStream fs = new FileStream("fs.txt", FileMode.Create))

{

SaveData(fs);

}

using(FileStream fs=new FileStream("fs.txt",FileMode.Open))

{

using (BinaryReader br = new BinaryReader(fs))

{

int fsLength =(int) fs.Length;

byte[] data = new byte[fsLength];

br.Read(data, 0, fsLength);

string str = Encoding.UTF8.GetString(data);

System.Diagnostics.Debug.WriteLine(str);

}

}

}

static void SaveData(Stream sm)

{

var bw = new BinaryWriter(sm);

for(int i=0;i<10000;i++)

{

string msg = $"Time {DateTime.Now.ToString("yyyyMMddHHmmssffff")},Guid {Guid.NewGuid()}\n";

bw.Write(msg);

}

bw.Flush();

}

static void LoadData(Stream sm)

{

var br = new BinaryReader(sm);

int smLength = (int)sm.Length;

byte[] byteArr = new byte[smLength];

br.Read(byteArr, 0, smLength);

string str = Encoding.UTF8.GetString(byteArr);

Console.WriteLine(str);

}

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:2019-11-29-浅谈-Windows-桌面端触摸架构演进
下一篇:ROS for Windows更新支持Turtlebot3、Moveit!和UR3
相关文章

 发表评论

暂时没有评论,来抢沙发吧~