zoukankan      html  css  js  c++  java
  • 写日志文件

    bool WriteTxtFile(string filename, string content)
    {
        bool bRet = false;
        FileStream fs = null;
        StreamWriter sw = null;
    
        try
        {
            FileInfo fi = new FileInfo(filename);
            if (!fi.Directory.Exists)
            {
                Directory.CreateDirectory(fi.Directory.FullName);
            }
                    
            //fs = new FileStream(filename, FileMode.Create, FileAccess.Write);
            fs = new FileStream(filename, FileMode.Append, FileAccess.Write);
            sw = new StreamWriter(fs, Encoding.Default);
            //DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss:fff:ffffff"))
            string s = string.Format("{0} {1}
    ", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss:fff"), content);
            sw.Write(s);
            sw.Flush();
            bRet = true;
        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.Message);
        }
        finally
        {
            if (sw != null)
                sw.Close();
            if (fs != null)
                fs.Close();
        }
    
        return bRet;
    }
  • 相关阅读:
    标准JSF的生命周期
    JSON
    Applet
    关于AJAX
    Java EE第十一周
    Java EE第八周
    Java EE第七周
    Java EE第六周
    Java EE第五周
    Java EE第四周
  • 原文地址:https://www.cnblogs.com/zhangmo/p/13822342.html
Copyright © 2011-2022 走看看