我有两个应用程序需要以快速的方式相互传递值,并且需要保留一些值(当我重新启动计算机时它仍然存在),所以我需要创建一个文件,现在我知道该怎么做了int: using (BinaryWriter writer = new BinaryWriter(new FileStream(@"C:\TEST", FileMode.Open))) { writer.Write(0); //00 00 00 00 writer.Write(1); //01 00 00 00 writer.Write(2); //02 00 00 00 writer.Write(3); //03 00 00 00 writer.Write(int.MaxValue); //FF FF FF 7F } byte[] test = new byte[4]; using (BinaryReader reader = new BinaryReader(new FileStream(@"C:\TEST", FileMode.Open))) { reader.BaseStream.Seek(8, SeekOrigin.Begin); reader.Read(test, 0, 4); Console.WriteLine(BitConverter.ToInt32(test, 0)); //2 reader.BaseStream.Seek(16, SeekOrigin.Begin); reader.Read(test, 0, 4); Console.WriteLine(BitConverter.ToInt32(test, 0)); //2147483647 Console.Read(); }可是怎么办double呢?
1 回答
慕丝7291255
TA贡献1859条经验 获得超6个赞
就这么简单
writer.Write((double)int.MaxValue);
Write(Double) 将一个八字节的浮点值写入当前流并将流位置前进八字节
至于读书
reader.ReadDouble()
- 1 回答
- 0 关注
- 161 浏览
添加回答
举报
0/150
提交
取消