C#txt文件创建并写入信息

        public static void LogWrite(string str)
        {
//项目根目录 string path = HttpContext.Current.Server.MapPath("~") + "ilogs.txt"; if (!File.Exists(path)) { FileStream fs = new FileStream(path, FileMode.Create,FileAccess.ReadWrite); StreamWriter sw = new StreamWriter(fs); sw.Write(str); sw.Flush(); sw.Close(); } else { FileStream fs = new FileStream(path, FileMode.Append); //文本写入 StreamWriter sw = new StreamWriter(fs); sw.Write(str); sw.Flush(); sw.Close(); } }

  

原文地址:https://www.cnblogs.com/Violety/p/10904807.html