主要有两个方面:
1、判断文件是否有内容;
2、如果有内容,怎么在内容的最后追加。

解决方案 »

  1.   

    1.
    StreamReader reader = null;
    reader=new StreamReader(Server.MapPath("foot.txt"),System.Text.Encoding.Default);
    string str_foot=reader.ReadToEnd().Trim();
    if(str_foot!=null)
    {
       2个问题不会
    }
      

  2.   

    判断已经有了
    这里给出追加的
    using System;
    using System.IO;
    using System.Text;class Test
    {
        public static void Main()
        {
            string path = @"c:\temp\MyTest.txt";        // This text is added only once to the file.
            if (!File.Exists(path))
            {
                // Create a file to write to.
                string createText = "Hello and Welcome" + Environment.NewLine;
                File.WriteAllText(path, createText);
            }        // This text is always added, making the file longer over time
            // if it is not deleted.
            string appendText = "This is extra text" + Environment.NewLine;
            File.AppendAllText(path, appendText);        // Open the file to read from.
            string readText = File.ReadAllText(path);
            Console.WriteLine(readText);
        }
    }
      

  3.   


    public void OK()
            {
                string path = "";//文件路径
                System.IO.StreamWriter writer = null;//写文件的类
                if (System.IO.File.Exists(path))
                {
                    writer = new System.IO.StreamWriter(System.IO.File.OpenWrite(path));
                }
                else
                {
                    writer = new System.IO.StreamWriter(System.IO.File.Create(path));
                }
                //writer.Write();//写入一个字符串
                //writer.WriteLine();//写入字符串之后换行
                writer.Close();//写完之后关闭
            }