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

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

2012-05-24 09:08 by swarb, ... 阅读, ... 评论, 收藏, 编辑

            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();

你可能感兴趣的:(C#为txt文件追加文字并换行)