C# 随笔写txt

public static void WriterFile(string file)
{
string path = AppDomain.CurrentDomain.BaseDirectory;
//如果不存在,则创建目录
if (!Directory.Exists(path + "Log/"))
{
Directory.CreateDirectory(path + "Log/");
}
FileStream fs = new FileStream(path + "\\Log/log" + DateTime.Now.ToString("yyyyMMdd") + ".txt", FileMode.Append);
StreamWriter streamWriter = new StreamWriter(fs);
streamWriter.BaseStream.Seek(0, SeekOrigin.End);
streamWriter.WriteLine(DateTime.Now.ToString() + " " + file);
streamWriter.Flush();
streamWriter.Close();
fs.Close();

}

上一篇:C#中的文件操作


下一篇:使用FileStream向txt格式的文本文件 "追加" 新内容并读取