读一行删一行 然后 Save一下阿

解决方案 »

  1.   

    把文本的内容倒到一个RichTextBox中,然后通过:
    while(rtb.Lines.Count>0)
    {
         //读取第一行,
         //删除第一行。
         //将结果存回文件。
    }
    应该就OK了。
      

  2.   

    还是不行
    我的.txt文件比较大,大概有几十M或上百M用这种方法明显不行的
    那要占用多少内存啊!
      

  3.   

    再vb6我作过这方面的,但是再.net下我没有作过
      

  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];
    FileStream fs=new FileStream(strLocalFileName,FileMode.Truncate,FileAccess.Write);
    StreamWriter sw=new StreamWriter(fs);

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

    }
      

  5.   

    jinbingg(bing) :采用的 FileMode.Truncate 将清除原来文件里的所有内容,不合要求hbxtlhx(下着春雨的天) :如果文件有几百M的话,你的方法明显是不行的
      

  6.   

    .net类库只提供,StreamReader 和StreamWriter
    但在Stream.ReadByte 从流中读取一个字节,并将流内的位置向前推进一个字节,或者如果已到达流的末尾,则返回 -1。但它返回的是一个int,把它们转换为字符比较麻烦
    有人知道有没有类似Stream.ReadByte 但返回类型是字符或字符串的方法?
    或者有那位大虾写了这种类,那出来大家贡享!