string path = @"C:\Users\Administrator\Desktop\1.txt";
                using (FileStream ws = new FileStream(path, FileMode.OpenOrCreate, FileAccess.Write))
                {
                    using (BinaryWriter bw = new BinaryWriter(ws))
                    {
                        bw.Write(123);
                        bw.Write(true);
                        bw.Write("hello world");
                    }
                }

                using (FileStream rs = new FileStream(path, FileMode.Open, FileAccess.Read))
                {
                    using (BinaryReader br = new BinaryReader(rs))
                    {
                        //读取的顺序必须和写入的顺序一致
                        int i = br.ReadInt32();
                        bool b = br.ReadBoolean();
                        string s = br.ReadString();
                        Console.WriteLine(i);
                        Console.WriteLine(b);
                        Console.WriteLine(s);
                    }
                }

 

相关文章:

  • 2021-12-10
  • 2022-01-24
  • 2021-07-22
  • 2021-07-14
  • 2022-12-23
  • 2022-12-23
  • 2021-05-23
  • 2022-12-23
猜你喜欢
  • 2021-11-04
  • 2021-09-07
  • 2021-09-26
  • 2022-12-23
  • 2021-09-27
  • 2022-12-23
相关资源
相似解决方案