查询是否有文件存在,如果不存在则创建
string path = AppDomain.CurrentDomain.BaseDirectory + DateTime.Now.Date.ToString("yyyy-MM-dd") + ".txt";
try
{
//判断文件是否存在,没有则创建。
if (!System.IO.File.Exists(path))
{
FileStream stream = System.IO.File.Create(path);
stream.Close();
stream.Dispose();
}
}
catch
{
}
在文件中写入:
using (StreamWriter writer = new StreamWriter(path, true))
{
writer.WriteLine("123" + " " + DateTime.Now.ToString() + DateTime.Now.ToString());
}