C# 二进制读取和保存文件

  			//已知文件大小的情况下读取
  			#region 二进制读取
            ushort[] rawdata = new ushort[num];
            BinaryReader br = new BinaryReader(new FileStream("binread.bin", FileMode.Open, FileAccess.Read));
            for (int i = 0; i < num; i++)
            {
                rawdata[i] = br.ReadUInt16();
            }
			#endregion
			//已知数据量的情况下保存
           #region 二进制保存
            BinaryWriter bw = new BinaryWriter(new FileStream("binwrite.bin", FileMode.Create, FileAccess.Write));

            for (int i = 0; i < num; i++)
            {
                bw.Write(rawdata[i]);
            }
            #endregion

你可能感兴趣的:(C# 二进制读取和保存文件)