005.File/FileHelper.cs

(开头部分) 6KB

这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。

#region -- 版 本 注 释 --
/****************************************************
* 文 件 名:
* Copyright(c) 王树羽
* CLR 版本: 4.5
* 创 建 人:王树羽
* 电子邮箱:674613047@qq.com
* 官方网站:https://www.cnblogs.com/shuyu
* 创建日期:2019-05-09
* 文件描述:
******************************************************
* 修 改 人:
* 修改日期:
* 备注描述:
*******************************************************/
#endregion

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;

namespace CommonLib
{
    /// <summary>
    /// 文件帮助类
    /// </summary>
    public class FileHelper
    {
        #region 文件读写

        /// <summary>
        /// 文件写入锁
        /// </summary>
        protected static object FileLock = new object();

        /// <summary>
        /// 文件写入方法
        /// </summary>
        /// <param name="path">文件路径:绝对路径</param>
        /// <param name="str">写入内容</param>
        /// <param name="append">是否追加</param>
        /// <param name="encoding">编码格式</param>
        public static void FileWrite(string path, string str, bool append = false, string encoding = "utf-8")
        {
            var dir = Path.GetDirectoryName(path);
            if (!Directory.Exists(dir))
            {
                Directory.CreateDirectory(dir);
            }
            System.Text.Encoding code = System.Text.Encoding.GetEncoding(encoding);
            System.IO.StreamWriter sw = null;
            try
            {
                lock (FileLock)
                {
                    sw = new System.IO.StreamWriter(path, append, code);
                    sw.Write(str);
                    sw.Flush();
后面还有 167 行代码,解锁后查看完整代码

24 小时内免费解锁 3 个项目,之后 1 积分/个。 规则说明

AI 解读

登录后可用,每次 10 积分,解读结果公开显示在下面。

还没有人解读过这个文件。