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(); } }

  

 

posted @ 2019-05-22 11:22  violety  阅读(5273)  评论(0编辑  收藏  举报