filestream里面也有指针吗?
好像不行...

解决方案 »

  1.   

    抽象类Stream在读写时,可以设置其偏移量(offset),例如要在流中从第1025个字节开始读取100byte,
    则是
    stream.Read( buffer , 1024 , 100 );
    对于所有继承Stream对象,当它为可读或可写时都可以。
    stream还有个属性position,表示流读写时的位置。
      

  2.   

    sorry,看错了。如果你知道从指定位置开始的某段数据是什么类型,可以使用binaryReader。
    FileStream fs;
    BinaryReader br = new BinaryReader( fs );
    br.BaseStream.Seek( 0 , SeekOrigin.Begin );
    ...
    //
    int a = br.ReadInt32();
    ...//continue to readingstring s = br.ReadString();
    ...bytes[] buffer = br.ReadBytes( 100 ); //read 100 bytes
      

  3.   

    那位大虾帮忙译成 C#代码//功能:初次使用时,在文件末部加入某个字符.
    DWORD num;
    UpdateData(1);
    num=m_jms;
    num^=0x1999aa98;
    if(num==m_gkh)
    MessageBox("ok");
    CFile ff;
    if(!ff.Open("play.exe",CFile::modeWrite))
    return;
    CString str;
    str.Format("%10d",m_jms);
    MessageBox(str);
    ff.SeekToEnd();
    ff.Write(str,10);//添加到play.exe尾部
    ff.Close();
      

  4.   

    /// <summary>
    /// 同步票号
    /// </summary> private void ProWriteTxt()
    {

    string strLocalFileName=Directory.GetCurrentDirectory() + @"\baseinfo.txt";
    string strInfo="";
    StreamReader  sr=new StreamReader((System.IO.Stream)File.OpenRead(strLocalFileName),System.Text.ASCIIEncoding.UTF8 )  ;
    strInfo=sr.ReadLine();
    sr.Close();
    string[] strSubInfo=strInfo.Split('#');//读过程

    strSubInfo[3]=this.lblPh.Text.ToString();//修改过程
    strInfo = strSubInfo[0]+"#"+strSubInfo[1]+"#"+strSubInfo[2]+"#"+strSubInfo[3]+"#"+strSubInfo[4]+"#"+strSubInfo[5]+"#"+strSubInfo[6]+"#"+strSubInfo[7];
    FileStream fs=new FileStream(strLocalFileName,FileMode.Truncate,FileAccess.Write);
    StreamWriter sw=new StreamWriter(fs);

    sw.WriteLine(strInfo);
    sw.Close();
    fs.Close();

    }
    我是用#分割的。
      

  5.   

    是添加还是在最后10个字节操作?
    //功能:初次使用时,在文件末部加入某个字符.
    uint num;               //DWORD num;
    UpdateData(1);  //??
    num=m_jms;
    num^=0x1999aa98;
    if(num==m_gkh)
    MessageBox("ok");
    FileStream fs = new FileStream( "play.exe" , FileMode.Append , FileAccess.OpenAndWrite );//if(!ff.Open("play.exe",CFile::modeWrite))
                              // return;
    string str = "" ;               // CString str;
    string = String.Format( m_jms , "0000000000" ); //str.Format("%10d",m_jms);
    MessageBox(str);
    fs.Seek( 0 , SeekOption.End );  // ff.SeekToEnd();
    BinaryWriter bw = new BinaryWriter( fs );
    bw.Write( str );        //  ff.Write(str,10);//添加到play.exe尾部
    bw.Close();
    fs.Close();                  //ff.Close();//have a try.
      

  6.   

    OneDotRed(武装到眼神):如何才能读取 刚才写入的那10个字符的内容,并修改呢,盼赐教!
      

  7.   

    使用binarywriter写字符串,它会默认在字符串后面加 "\0",由实际的10个字节变为11个字节。建议直接写如byte数组。int i = 10245679;
    string str = t.ToString( "0000000000" );byte[] buffer = System.Text.Encoding.Default.GetBytes( str );FileStream fs = new FileStream( fileName , FileMode.Open , FileAccess.ReadAndWrite );
    fs.Seek( 0 , SeekOrigin.End );        //当前fs的position再其文件末尾
    fs.Write( buffer , 0 , buffer.Length ); //写入byte数组
    fs.Close(); ----------------------------------读取:
    FileStream fs = new FileStream( fileName , FileMode.Open , FileAccess.ReadAndWrite );
    fs.Seek( -10 , SeekOrigin.End );          
    byte[] buffer = new byte[ 10 ];
    fs.Read( buffer , 0 , 10 );
    fs.Close();string str = Encoding.Defauult.GetString( buffer );
      

  8.   

    非常感谢OneDotRed(武装到眼神)。