• C# 创建txt文本


    /// <summary>
            /// log日志,txt的
            /// </summary>
            /// <param name="Log1">内容</param>
            /// <param name="name">名字</param>
            /// <param name="path">路径</param>
            public void Logmsg(string Log1, string name, string path)
            {
                #region 创建日志
                Log = "";
                Log += Log1 + "
    ";
    
                //生成目录
                //创建文件夹
                if (Directory.Exists(path) == false)//如果不存在就创建file文件夹
                {
                    Directory.CreateDirectory(path);
                }
    
                // 判断文件是否存在,不存在则创建,否则读取值显示到txt文档
                if (!System.IO.File.Exists(path + "/" + name + "_Log" + DateTime.Today.ToString("yyyy-MM-dd") + ".txt"))
                {
                    FileStream fs1 = new FileStream(path + "/" + name + "_Log" + DateTime.Today.ToString("yyyy-MM-dd") + ".txt", FileMode.Create, FileAccess.Write);//创建写入文件 
                    StreamWriter sw = new StreamWriter(fs1);
                    sw.WriteLine(Log);//开始写入值
                    sw.Close();
                    fs1.Close();
                }
                else
                {
                    FileStream fs = new FileStream(path + "/" + name + "_Log" + DateTime.Today.ToString("yyyy-MM-dd") + ".txt" + "", FileMode.Append, FileAccess.Write);
                    StreamWriter sr = new StreamWriter(fs);
                    sr.WriteLine(Log);//开始写入值
                    sr.Close();
                    fs.Close();
                }
                #endregion
            }
  • 相关阅读:
    P1071 潜伏者
    P2199 最后的迷宫
    推荐
    T150191 求和
    T150189 养猪
    P1106 删数问题
    NOIP 2018 提高组初赛试题胡谈
    结题报告
    博客迁移公告
    简单实用算法——用队列实现栈
  • 原文地址:https://www.cnblogs.com/duhaoran/p/13824736.html
Copyright © 2020-2023  润新知