Browse Source

文本工具,追加选项可配置

yuzhengyang 3 years ago
parent
commit
128c9bfffa
1 changed files with 5 additions and 5 deletions
  1. 5 5
      Azylee.Utils/Azylee.Core/IOUtils/TxtUtils/TxtTool.cs

+ 5 - 5
Azylee.Utils/Azylee.Core/IOUtils/TxtUtils/TxtTool.cs

@@ -15,12 +15,12 @@ namespace Azylee.Core.IOUtils.TxtUtils
 {
     public class TxtTool
     {
-        public static bool Append(string file, List<string> txt)
+        public static bool Append(string file, List<string> txt, bool append = true)
         {
             try
             {
                 DirTool.Create(Path.GetDirectoryName(file));
-                using (StreamWriter sw = new StreamWriter(file, true))
+                using (StreamWriter sw = new StreamWriter(file, append))
                 {
                     if (!ListTool.IsNullOrEmpty(txt))
                         foreach (var t in txt)
@@ -31,12 +31,12 @@ namespace Azylee.Core.IOUtils.TxtUtils
             catch (Exception e) { }
             return false;
         }
-        public static bool Append(string file, string txt)
+        public static bool Append(string file, string txt, bool append = true)
         {
             try
             {
                 DirTool.Create(Path.GetDirectoryName(file));
-                using (StreamWriter sw = new StreamWriter(file, true))
+                using (StreamWriter sw = new StreamWriter(file, append))
                 {
                     sw.WriteLine(txt);
                 }
@@ -107,7 +107,7 @@ namespace Azylee.Core.IOUtils.TxtUtils
             }
             catch (Exception e) { }
         }
-        public static void ReadLine(string file,Encoding encoding, Action<int, string> action)
+        public static void ReadLine(string file, Encoding encoding, Action<int, string> action)
         {
             try
             {