写入文件(txt格式)

时间:2024-12-17 13:05:20

#region 写入文件
       /// <summary>
       /// 写入文件
       /// </summary>
       /// <param name="TXTName">文件名称</param>
       /// <param name="Message">写入内容</param>
        private static void WriteFile(string TXTName, string Message)
        {
            string url = "" + Application.StartupPath + "\\" + TXTName + ".txt";
            FileStream fs = new FileStream(url, FileMode.Append);
            StreamWriter sw = new StreamWriter(fs);
            sw.BaseStream.Seek(0, SeekOrigin.End);
            sw.WriteLine(DateTime.Now + ":" + Message);
            sw.Close();
            fs.Close();
        }
        #endregion