/// <summary>        
/// 将文本写入文本文件        
/// </summary>        
/// <param name="name">完整文件名</param>        
/// <param name="content">内容</param>        
/// <param name="isCover">是否覆盖存在文件</param>        
public static void WriteToFile(string name, string content, bool isCover)        
{            FileStream fs = null;
            try
            {
                if (!isCover && File.Exists(name))
                {
                    fs = new FileStream(name, FileMode.Append, FileAccess.Write);
                    StreamWriter sw = new StreamWriter(fs, Encoding.UTF8);
                    sw.WriteLine(content);
                    sw.Flush();
                    sw.Close();
                }
                else
                {
                    File.WriteAllText(name, content, Encoding.UTF8);
                }
            }
            finally
            {
                if (fs != null)
                {
                    fs.Close();
                }
            }
        }

 

相关文章:

  • 2022-12-23
  • 2022-02-12
  • 2022-12-23
  • 2021-08-15
  • 2022-12-23
  • 2021-08-19
  • 2021-12-28
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-12-26
  • 2021-04-12
  • 2021-06-13
  • 2021-12-05
  • 2022-02-08
相关资源
相似解决方案