C#为txt文件追加文字并换行

来源:互联网 发布:淘宝新店做什么活动 编辑:程序博客网 时间:2024/05/14 01:59

            string path= System.Windows.Forms.Application.StartupPath + "\\ErrorLog\\"+fileName +".txt";
            if (!File.Exists(path))
            {
                FileInfo myfile = new FileInfo(path);
                FileStream fs = myfile.Create();
                fs.Close();
            }
            StreamWriter sw = File.AppendText(path);
            sw.WriteLine(errorMsg);
            sw.Flush();
            sw.Close();

原创粉丝点击