C# 保存文本txt 保存日志 保存.txt

    public void SaveFile()
        {
            string stream = null;
            if (File.Exists("log.txt"))
            {
                StreamReader reader = new StreamReader("log.txt");
                stream = reader.ReadToEnd();
                reader.Close();
            }

            FileStream fs = new FileStream("log.txt", FileMode.OpenOrCreate);
            StreamWriter sw = new StreamWriter(fs);
            sw.WriteLine(stream);
            sw.WriteLine();
            sw.WriteLine("***********************************************************************");
            sw.WriteLine(DateTime.Now);
            sw.WriteLine("ADD:");
            sw.WriteLine("1: 10234 刘辉 55 美国二部 11 美国第一事业部 224 北京公司");
            sw.WriteLine("2: 10234 刘辉 55 美国二部 11 美国第一事业部 224 北京公司");

            sw.WriteLine("UPDATE:");
            sw.WriteLine("1: 10234 刘辉 55 美国二部 11 美国第一事业部 224 北京公司 改为 10234 刘辉 55 美国二部 11 美国第一事业部 224 北京公司");
            sw.WriteLine("1: 10234 刘辉 55 美国二部 11 美国第一事业部 224 北京公司 改为 10234 刘辉 55 美国二部 11 美国第一事业部 224 北京公司");


            sw.Close();
            fs.Close();



        }