zoukankan      html  css  js  c++  java
  • c# 写txt文件

    public static void WriteErrorLogDataInteraction(string sLog, string titleLog)
            {
                try
                {
                    string logPath = ConfigurationSettings.AppSettings["LogPath"]; //通过配置文件记录错误日志位置
                    if (string.IsNullOrEmpty(logPath))
                    {
                        logPath = System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase;//配置文件安装目录
                    }
                    DateTime dt = DateTime.Now;
                    string logfile = new StringBuilder(logPath).Append(DateTime.Now.ToString("yyyy-MM")).Append(".txt").ToString();
                    if (!System.IO.Directory.Exists(System.IO.Path.GetDirectoryName(logfile)))
                    {
                        System.IO.Directory.CreateDirectory(System.IO.Path.GetDirectoryName(logfile));
                    }
                    if (!File.Exists(logfile))
                    {
                        FileStream fs = System.IO.File.Create(logfile);
                        fs.Close();
                    }
                    using (StreamWriter sw = new StreamWriter(logfile, true))
                    {
                        sw.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + ":");
                        sw.WriteLine("Title: " + titleLog);
                        sw.WriteLine("Message:" + sLog);
                        sw.WriteLine();
                        sw.Close();
                    }
                }
                catch
                { }
            }

    方式二、

    string a = rea.ToString();


            StreamWriter bb = new StreamWriter("c:\\bbb.xml");


            bb.Write(a);


            bb.Close();

  • 相关阅读:
    vector 向量容器用法祥解
    stdafx.h 的作用
    vector 利用swap 函数进行内存的释放 vector<int>().swap
    LPCTSTR LPCWSTR LPCSTR 含义
    Application->ProcessMessages();
    sizeof 和 strlen 的区别
    程序编译没错,运行报错:无法定位程序输入点GT_BufLaserFollowRatio(这是函数)于动态链接库GTS.DLL上
    用户登录注销功能
    在项目开发中经常用到的全局函数
    在项目开发中经常用到的全局函数2
  • 原文地址:https://www.cnblogs.com/honghong75042/p/5773957.html
Copyright © 2011-2022 走看看