码迷,mamicode.com
首页 > 其他好文 > 详细

把内容生成txt文件

时间:2016-11-21 19:57:08      阅读:154      评论:0      收藏:0      [点我收藏+]

标签:name   cto   pen   catch   app   encoding   bsp   rect   append   

           StringBuilder MailLog = new StringBuilder();

            string logPath = txtFile + str + DateTime.Now.ToString("yyyyMMdd") + ".txt";

            Write(logPath, Context.DateFormat + " - " + message);

 

public static void Write(string filePath, string message, bool isNewline = true, Encoding encoding = null, bool append = true)
        {
            encoding = encoding ?? SlEncoding.Default;

            try
            {
                Directory.CreateDirectory(Path.GetDirectoryName(filePath));
            }
            catch { }

            using (var streamWriter = new StreamWriter(filePath, append, encoding))
            {
                if (isNewline)
                {
                    streamWriter.WriteLine(message);
                }
                else
                {
                    streamWriter.Write(message);
                }
                streamWriter.Flush();
            }
        }

把内容生成txt文件

标签:name   cto   pen   catch   app   encoding   bsp   rect   append   

原文地址:http://www.cnblogs.com/sk2016/p/6086287.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!