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

    写入Txt文件方法
     1    private static void WriteTxt(string fullFilepath, string Content)
     2         {
     3             StreamWriter Sw1 = null;
     4             try
     5             {
     6 
     7                 CreatePath(GetFilePath(fullFilepath));
     8                 Sw1 = new StreamWriter(fullFilepath, true, Encoding.UTF8);
     9                 {
    10                     Sw1.WriteLine(Content);
    11                 }
    12             }
    13             catch (Exception ef)
    14             {
    15                 throw new Exception(ef.Message);
    16             }
    17             finally
    18             {
    19                 try
    20                 {
    21                     Sw1.Close();
    22                 }
    23                 catch
    24                 {
    25                 }
    26             }
    27         }
    View Code
    去出文件所有路径
    1  public static string GetFilePath(string FileName)
    2         {
    3             string sFile = FileName;
    4             sFile = sFile.Substring(0, sFile.LastIndexOf("\"));
    5             return sFile;
    6         }
    View Code
    创建路径
     1  public static bool CreatePath(string path)
     2         {
     3             try
     4             {
     5                 if (!HasFilePath(GetFilePath(path)))
     6                 {
     7                     CreatePath(GetFilePath(path));
     8                 }
     9                 Directory.CreateDirectory(path);
    10                 return true;
    11             }
    12             catch (Exception ee)
    13             {
    14                 throw new Exception(ee.Message);
    15             }
    16         }
    View Code
    文件所在路径是否存在
    1   public static bool HasFilePath(string FileName)
    2         {
    3             if ((FileName.Length == 2) && (FileName.LastIndexOf(':') > 0))
    4                 return true;
    5             return Directory.Exists(GetFilePath(FileName));
    6         }
    View Code
  • 相关阅读:
    [转载]解析用户生命周期价值:LTV
    [整理]VS2013常用插件
    Extjs4 tabpanel 中表单定宽居中
    idea创建ssm项目
    shiro框架的学习
    mysql
    springboot
    idea配置
    Spring MVC
    关于web乱码问题
  • 原文地址:https://www.cnblogs.com/dot-caohui/p/10873972.html
Copyright © 2011-2022 走看看