简单的办法,用StreamReader打开文件,读出内容,末尾加上要追加的字符窜,再用StreamWriter写入文件。

解决方案 »

  1.   

    System.IO.FileInfo mFile
    =new System.IO.FileInfo("c:\\1.txt");
    System.IO.FileStream mStream
    = mFile.Open(System.IO.FileMode.Append,
    System.IO.FileAccess.ReadWrite);
    .......
      

  2.   

    public void WriteFileByFileStream(string filePath)
    {
    //初始化FileStream方法一
    //FileStream fs=new FileStream("",FileMode.Create,FileAccess.Write,FileShare.None);
    //初始化FileStream方法二
    FileInfo theFile=new FileInfo(filePath);
    FileStream fs=theFile.OpenWrite();
    //从流中写入一个字节
    // int nextbyte=100;
    // fs.WriteByte((byte)nextbyte);
    //从流中写入特定数量的字节数。
    string strTemp="hello,china";
    byte[] byteArray=System.Text.Encoding.ASCII.GetBytes(strTemp);
    fs.Write(byteArray,0,byteArray.Length);
    fs.Close();
    }
    public void WriteFileByStreamReader(string filePath)
    {
    //初始化streamreader
    StreamWriter sw=new StreamWriter(filePath);
    //写入一行
    sw.WriteLine("nihao哈暗黑!");
    //写入一个字符
    sw.Write('a');
    sw.Close();
    }
      

  3.   

    再看看微软的实例:Imports System
    Imports System.IOPublic Class Test
        Public Shared Sub Main()
            Dim path As String = "c:\temp\MyTest.txt"
            Dim sw As StreamWriter        ' This text is added only once to the file.
            If File.Exists(path) = False Then
                ' Create a file to write to.
                sw = File.CreateText(path)            sw.WriteLine("Hello")
                sw.WriteLine("And")
                sw.WriteLine("Welcome")
                sw.Flush()
                sw.Close()
            End If        ' This text is always added, making the file longer over time
            ' if it is not deleted.
            sw = File.AppendText(path)
            sw.WriteLine("This")
            sw.WriteLine("is Extra")
            sw.WriteLine("Text")
            sw.Flush()
            sw.Close()        ' Open the file to read from.
            Dim sr As StreamReader = File.OpenText(path)
            Dim s As String
            Do While sr.Peek() >= 0
                s = sr.ReadLine()
                Console.WriteLine(s)
            Loop
            sr.Close()
        End Sub
    End Class
      

  4.   

    System.IO.FileInfo f=new System.IO.FileInfo(@"d:\ttt.txt");
    System.IO.FileStream s= f.Open(System.IO.FileMode.Append, System.IO.FileAccess.ReadWrite);
    主要是上面的append
      

  5.   

    42
    主要是个append
    不过好像有个类直接有appendtext方法
    查查msdn
      

  6.   

    ....只是简单的向文本中追加文本?StreamWriter sw=new StreamWriter(@"C:\文.txt",true,System.Text.Encoding.Default);
    sw.Write(t.Text);
    sw.Close();这样就行了.
      

  7.   

    补充下:
    那第二个参数为  append  如果文件存在,而且 append 为真时,则向文件中追加.
    如果 append 为假,则改写文件.