====================================写
string time = System.DateTime.Now.ToShortTimeString();
string text = TextBox1.Text;
string sss = System.DateTime.Now.ToShortDateString()+".txt";
//指定路径
sss = "d:\\"+sss;
//如果文件a.txt存在就打开,不存在就新建 .append 是追加写
FileStream fst = new FileStream(sss,FileMode.Append);
//写数据到a.txt格式
StreamWriter swt = new StreamWriter(fst,System.Text.Encoding.GetEncoding("utf-8"));
//写入
swt.WriteLine(time+'\r'+"写"+text);
swt.Close();
fst.Close();
======================================== 读
string ss = System.DateTime.Now.ToShortDateString()+".txt";
ss ="d:\\"+ss;
//FileStream fs = new FileStream(sss,
try
{
StreamReader srt = new StreamReader(ss,Convert.ToBoolean(FileMode.Open));
//存在
TextBox2.Text = srt.ReadToEnd();
srt.Close();
}
catch(FileNotFoundException ee)
{
TextBox2.Text = ee.ToString();
}