using System; using System.IO; using System.Text; namespace Core.Util { ///
<summary> /// File read and write operation help class /// </summary> public class FileHelper { #region Read operation
/// <summary> /// Determine whether the file exists /// </summary> /// <param name="path"> File directory </param>
/// <returns></returns> public static bool Exists(string path) { return File.
Exists(path); } /// <summary> /// Get current program root directory /// </summary> ///
<returns></returns> public static string GetCurrentDir() { return AppDomain.
CurrentDomain.BaseDirectory; } #endregion #region Write operation /// <summary> /// Output string to file
/// notes : Use system default encoding ; If the file does not exist, a new one is created , If it exists, it will be covered /// </summary> /// <param
name="content"> content </param> /// <param name="path"> File path </param> public static void
WriteTxt(string content, string path) { WriteTxt(content, path, null, null); }
/// <summary> /// Output string to file /// notes : Use custom encoding ; If the file does not exist, a new one is created , If it exists, it will be covered /// </summary> ///
<param name="content"> content </param> /// <param name="path"> File path </param> /// <param
name="encoding"> code </param> public static void WriteTxt(string content, string
path, Encoding encoding) { WriteTxt(content, path, encoding, null); } ///
<summary> /// Output string to file /// notes : Use custom mode , use UTF-8 code /// </summary> /// <param
name="content"> content </param> /// <param name="path"> File path </param> /// <param
name="fileModel"> Output method </param> public static void WriteTxt(string content, string
path, FileMode fileModel) { WriteTxt(content, path, Encoding.UTF8, fileModel);
} /// <summary> /// Output string to file /// notes : Use custom encoding and write mode /// </summary> /// <param
name="content"> content </param> /// <param name="path"> File path </param> /// <param
name="encoding"> Character encoding </param> /// <param name="fileModel"> Write mode </param> public
static void WriteTxt(string content, string path, Encoding encoding, FileMode
fileModel) { WriteTxt(content, path, encoding, (FileMode?)fileModel); } ///
<summary> /// Output string to file /// notes : Use custom encoding and write mode /// </summary> /// <param
name="content"> content </param> /// <param name="path"> File path </param> /// <param
name="encoding"> Character encoding </param> /// <param name="fileModel"> Write mode </param> private
static void WriteTxt(string content, string path, Encoding encoding, FileMode?
fileModel) { encoding = encoding ?? Encoding.UTF8; fileModel = fileModel ??
FileMode.Create; string dir = Path.GetDirectoryName(path); if (!Directory.Exists
(dir)) Directory.CreateDirectory(dir); using (FileStream fileStream = new
FileStream(path, fileModel.Value)) { using (StreamWriter streamWriter = new
StreamWriter(fileStream, encoding)) { streamWriter.Write(content); streamWriter.
Flush(); } } } /// <summary> /// Output log to the specified file /// </summary> /// <param
name="msg"> Log messages </param> /// <param name="path"> Log file location ( The default is D:\ test \a.log)</param>
public static void WriteLog(string msg, string path = @"Log.txt") { string
content= $"{DateTime.Now.ToCstTime().ToString("yyyy-MM-dd HH:mm:ss")}:{msg}";
WriteTxt(content, $"{GetCurrentDir()}{content}"); } #endregion } }

Technology
©2019-2020 Toolsou All rights reserved,
It's unexpected Python Cherry tree (turtle The gorgeous style of Library )Unity3D of UGUI Basics -- Three modes of canvas os Simple use of module computer network --- Basic concepts of computer network ( agreement , system )html Writing about cherry trees , Writing about cherry trees Some East 14 Pay change 16 salary , Sincerity or routine ?Unity-Demo Examples ✨ realization UI- Backpack equipment drag function 06【 Interpretation according to the frame 】 Data range filtering -- awesome java Four functional interfaces ( a key , simple )