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

  

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM