Exemplo n.º 1
0
        /// <summary>
        /// 写入文本文件内容
        /// </summary>
        /// <param name="FilePath">文件路径</param>
        /// <param name="Content">文件内容</param>
        /// <param name="WriteType">写入方式:1-覆盖;2-追加</param>
        /// <param name="Enc">编码方式</param>
        public static void WriteText(string FilePath, string Content, TextWriteType WriteType, Encoding Enc)
        {
            try
            {
                string direct = System.IO.Path.GetDirectoryName(FilePath);
                if (!Directory.Exists(direct))
                {
                    Directory.CreateDirectory(direct);
                }

                if (WriteType == TextWriteType.Append)
                {
                    File.AppendAllText(FilePath, Content, Enc);
                }
                else if (WriteType == TextWriteType.Covered)
                {
                    File.WriteAllText(FilePath, Content, Enc);
                }
            }
            catch (Exception ex)
            {
                ex.WriteFile("FileHelper.WriteText", "写入文件路径:" + FilePath);
            }
        }
Exemplo n.º 2
0
 /// <summary>
 /// 写入文本文件内容
 /// </summary>
 /// <param name="FilePath">文件路径</param>
 /// <param name="Content">文件内容</param>
 /// <param name="WriteType">写入方式:1-覆盖;2-追加</param>
 public static void WriteText(string FilePath, string Content, TextWriteType WriteType)
 {
     WriteText(FilePath, Content, WriteType, Encoding.UTF8);
 }