1,string s= 读出内容;
2,关闭 file 句柄
3,执行 reaplce
4,写入 s你第2 步没有做才会出现同时读写的情况

解决方案 »

  1.   

    FileStream fs = new FileStream("c:\\table.htm", FileMode.Open);
    byte[] bytes = new Byte[(int)fs.Length];
    fs.Read(bytes, 0, bytes.Length);
    fs.Close();
    string strContent = System.Text.Encoding.GetEncoding("gb2312").GetString(bytes);
    int iStart = strContent.IndexOf("<body");
    int iEnd = strContent.IndexOf(">", iStart + 5);
    string strBody = strContent.Substring(iStart, iEnd - iStart + 1);
    if(strBody.ToLower().IndexOf("bgcolor") == -1)
    {
    //无bgcolor
    strContent = strContent.Insert(iEnd, " bgcolor='#cccccc'");
    }
    fs = new FileStream("c:\\table.htm", FileMode.Open, FileAccess.ReadWrite);
    bytes = System.Text.Encoding.GetEncoding("gb2312").GetBytes(strContent);
    fs.Write(bytes, 0, bytes.Length);
    fs.Flush();
    fs.Close();
      

  2.   

    to  panyee(快乐王子) ( ) 信誉:100 
    好像这样不行,把所有的内容放入内存中,很多人访问的话,服务器会受不了的。
    但多谢各位。
    能不能只读一行,现在我能读出来,但不知在知道在哪一行之后如何同时对文件进行写操作。
      

  3.   

    能否实现在一个上录下,如果有文件被上传(用ftp)来之后,对新的文件进行操作(进行上面的操作)。