c#怎么把int型数据存入FileStream.write(byte[] array,,int offset,int count)文件流

解决方案 »

  1.   

    BinaryWriter bw=new BinaryWriter();
    bw.Write();
    bw.Close();
    用这个比较好。
      

  2.   

    public virtual void Write(int value)
    {
          this._buffer[0] = (byte) value;
          this._buffer[1] = (byte) (value >> 8);
          this._buffer[2] = (byte) (value >> 0x10);
          this._buffer[3] = (byte) (value >> 0x18);
          this.OutStream.Write(this._buffer, 0, 4);
    }
     
    非要用FileStream,看上面的吧。上面就是bw.Write()的源码。
      

  3.   

    用BinaryWriter更方便了 public static void WriteData(BinaryWriter dout, int l, DataType[] type, object[] data) 
    {
    for (int i = 0; i < l; i++) 
    {
    object o = data[i]; if (o == null) 
    {
    dout.Write((int)DataType.Null);

    else 
    {
    DataType t = type[i]; dout.Write((int)t); switch (t) 
    {
    case DataType.Null:
    o = null;
    break;
    case DataType.SmallInt:
    dout.Write((Int16)o);
    break;
    case DataType.Int:
    dout.Write((Int32)o);
    break;
    case DataType.BigInt:
    dout.Write((Int64)o);
    break;
    case DataType.Real:
    dout.Write((float)0);
    break;
    case DataType.Float:
    dout.Write((Double)o);
    break;
    case DataType.Money:
    case DataType.SmallMoney:
    case DataType.Decimal:
    dout.Write((Decimal)o);
    break;
    case DataType.Bit:
    dout.Write((bool)o);
    break;
    case DataType.TinyInt:
    dout.Write((byte)o);
    break;
    case DataType.Binary:
    case DataType.VarBinary:
    case DataType.Image:
    case DataType.Variant:
    case DataType.Timestamp:
    byte[] b = ((ByteArray)o).Data;
    dout.Write(b.Length);//写入bit数组长度
    dout.Write(b);//写入数据
    break; default:
    dout.Write(o.ToString());
    break;
    }
    }
    }
    }
      

  4.   

    [size=13px][/size]