zoukankan      html  css  js  c++  java
  • 关于Log文本的操作

    // <summary>
    /// 创建文本
    /// </summary>
    /// <param name="ID"></param>
    /// <param name="content"></param>
    private static void AssetsWrite(string ID, string content)
    {
    try
    {
    string path = Path.Combine(AssetsPath, ID + ".log");
    if (File.Exists(path))
    {
    throw new AthException("文件已存在");
    }
    else
    {
    FileStream myFs = new FileStream(path, FileMode.Create);
    StreamWriter mySw = new StreamWriter(myFs, Encoding.UTF8);
    mySw.Write(content);
    mySw.Close();
    myFs.Close();
    }
    }
    catch (AthException athex)
    {
    throw athex;
    }
    catch (Exception ex)
    {
    throw ex;
    }
    }

    /// <summary>
    /// 读取文本内容
    /// </summary>
    /// <param name="path"></param>
    /// <returns></returns>
    private static string FileReadContent(string path)
    {
    try
    {
    FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
    StreamReader sr = new StreamReader(fs, System.Text.Encoding.UTF8);
    StringBuilder sb = new StringBuilder();
    string content = sr.ReadLine();
    sr.Close();
    return content;
    }
    catch (Exception ex)
    {
    throw ex;
    }

    }

    /// <summary>
    /// 获取文件夹文件
    /// </summary>
    /// <param name="path"></param>
    /// <returns></returns>
    private static List<string> GetFileName(string path)
    {

    List<string> logList = new List<string>();
    try
    {
    if (!string.IsNullOrEmpty(path))
    {
    DirectoryInfo folder = new DirectoryInfo(path);
    foreach (FileInfo file in folder.GetFiles("*.log"))
    {
    logList.Add(file.Name);
    }
    }
    else
    {
    throw new AthException("路径不完善");
    }
    }
    catch (AthException athex)
    {
    throw athex;
    }
    catch (Exception)
    {

    throw;
    }

    return logList;
    }

    /// <summary>
    /// 删除文件
    /// </summary>
    /// <param name="path"></param>
    private static void DeleteFile(string path)
    {
    try
    {
    if (!File.Exists(path)) return;
    FileAttributes attr = File.GetAttributes(path);
    if (attr == FileAttributes.Directory)
    {
    //删除文件夹
    Directory.Delete(path, true);
    }
    else
    {
    //删除文件
    File.Delete(path);
    }
    }
    catch (Exception ex)
    {
    throw ex;
    }

    }

    }

    作者:D调灬仔
    出处:https://www.cnblogs.com/chj929555796/
    您的推荐是我最大的动力,如果觉得这篇文章对你有帮助的话,请点个“推荐”哦,博主在此感谢!
  • 相关阅读:
    jquery使用
    网站重构?
    WEB应用从服务器主动推送Data到客户端有那些方式?
    异步加载和延迟加载?
    平时如何管理你的项目?
    对前端界面工程师这个职位是怎么样理解的?它的前景会怎么样?
    约定优于配置(convention over configuration)
    JavaEE的13种核心技术
    The Spring Framework ConfigurableListableBeanFactory.java
    mySQL的boolean类型为tinyint(1)
  • 原文地址:https://www.cnblogs.com/chj929555796/p/9442778.html
Copyright © 2011-2022 走看看