asp.net 追加文本(追加写入记事本)
代码:
1 string path = Server.MapPath("/Log/Log.txt"); 2 if (File.Exists(path)) 3 { 4 using (StreamWriter sw = File.AppendText(path)) 5 { 6 sw.WriteLine("文本内容"); 7 sw.Flush(); 8 sw.Close(); 9 } 10 } 11 else 12 { 13 using (StreamWriter sw = File.CreateText(path)) 14 { 15 sw.WriteLine("文本内容"); 16 sw.Flush(); 17 sw.Close(); 18 } 19 }