zoukankan      html  css  js  c++  java
  • 把内容生成txt文件

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

  • 相关阅读:
    迭代器和生成器
    20.03.23作业
    装饰器
    集合
    元组类型
    字典类型
    列表类型
    字符串类型
    for循环
    深浅copy与while循环
  • 原文地址:https://www.cnblogs.com/sk2016/p/6086287.html
Copyright © 2011-2022 走看看