C# 操作文本 读写日志

原创
2016/06/18 00:31
阅读数 455
        /// <summary>
        /// 写入数据
        /// </summary>
        /// <param name="io">文件内容</param>
        public static void Write(string io)
        {
            string path = "Logs\\errorlogs.txt";
            if (!File.Exists(path))
            {
                //将异常显示到文本框中

                FileInfo myfile = new FileInfo(path);
                FileStream fs = myfile.Create();
                fs.Close();

            }
            StreamWriter sw = File.AppendText(path);
            //开始写入
            sw.Write(io + "\r\n");

            //清空缓冲区
            sw.Flush();
            //关闭流
            sw.Close();
            //fs.Close();
        }

        /// <summary>
        /// 写入数据
        /// </summary>
        /// <param name="io">文件内容</param>
        public static void WriteNull(string io)
        {
            string path = "Logs\\errorlogs.txt";
            if (!File.Exists(path))
            {
                //将异常显示到文本框中

                FileInfo myfile = new FileInfo(path);
                FileStream fs = myfile.Create();
                fs.Close();

            }
            StreamWriter sw = new StreamWriter(path);

            //开始写入
            sw.Write(io);

            //清空缓冲区
            sw.Flush();
            //关闭流
            sw.Close();
            //fs.Close();
        }

 

展开阅读全文
c#
加载中
点击引领话题📣 发布并加入讨论🔥
0 评论
0 收藏
0
分享
返回顶部
顶部