public void FileStream() { FileStream file; string fileName=AppDomain.CurrentDomain.BaseDirectory+"\\log.txt"; //应用程序根地址 if (!File.Exists(fileName)) { file = new FileStream(fileName, FileMode.Create); //创建文件 } else { file = new FileStream(fileName, FileMode.Append); //文件后面追加文本 } using(StreamWriter streamWriter = new StreamWriter(file)) { streamWriter.WriteLine(DateTime.Now.ToString()); streamWriter.Flush(); //将缓存数据写入流,并清除当前缓存数据 } }
原文地址:http://www.cnblogs.com/yaoxing92/p/3857976.html