// <summary>
/// 检查是否存在文件夹
/// </summary>
public void change()
{
string path = Application.StartupPath + "\\" + DateTime.Now.ToString("yyyy-MM-dd") + "\\TextMessage.txt";
if (!Directory.Exists(Application.StartupPath + "\\" + DateTime.Now.ToString("yyyy-MM-dd")))
{
Directory.CreateDirectory(Application.StartupPath + "\\" + DateTime.Now.ToString("yyyy-MM-dd"));
}
if (!File.Exists(path))
{
FileStream fs = File.Create(@"" + DateTime.Now.ToString("yyyy-MM-dd") + "\\TextMessage.txt");
fs.Close();
}
}
/// <summary>
/// 写入文本文件
/// </summary>
/// <param name="value"></param>
public void text(string value)
{
change();
string path = Application.StartupPath + "\\" + DateTime.Now.ToString("yyyy-MM-dd") + "\\TextMessage.txt";
FileStream f = new FileStream(path, FileMode.Append, FileAccess.Write, FileShare.ReadWrite);
StreamWriter sw = new StreamWriter(f);
sw.WriteLine(value);
sw.Flush();
sw.Close();
f.Close();
}
转载于:https://www.cnblogs.com/sy9603/p/4592638.html