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,
Conflict statement (conflicting declaration) solve Vue Transfer parameters and receiving of page Jump python in switch_to_alert Usage of el-select At the same time label and value value Three methods of value transfer between non parent and child components mysql No backup recovery 11-5 Output string at specified position springboot Multi profile configuration centos lower zip Compression and decompression command Map---Java judge Map Contains a key