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
  • 相关阅读:
    Uva 11806 拉拉队 二进制+容斥原理 经典!
    CSU CHESS
    hdu 4049 Tourism Planning 状态压缩dp
    HDOJ 4661: Message Passing(找递推公式+逆元)
    HDU
    hdu4647(思路啊!)
    spoj 370. Ones and zeros(搜索+同余剪枝+链表存数(可能越界LL))
    URAL
    URAL
    hdu4614 (二分线段树)
  • 原文地址:https://www.cnblogs.com/dot-caohui/p/10873972.html
Copyright © 2011-2022 走看看