C# 向txt文件中写入

        /// <summary>
        /// 向txt文件中写入信息
        /// </summary>
        /// <param name="filePath"></param>
        /// <param name="massage"></param>
        public static void WriteTxt(string filePath, string massage)
        {
            FileStream fs1;

            //判断是否已经有了这个文件
            if (!File.Exists(filePath))
            {
                //没有则创建这个文件
                fs1 = new FileStream(filePath, FileMode.Create);//创建写入文件   
            }


            using (StreamWriter sw = File.AppendText(filePath))
            {
                sw.WriteLine(massage);
            }



        }
原文地址:https://www.cnblogs.com/catherinehu/p/12153343.html