写文件
var str=“十年磨一剑”;
var txtPath = "C:\\MergeData.txt";
FileStream fs;
StreamWriter sw;
fs = new FileStream(txtPath,FileMode.Create,FileAccess.Write);
sw= new StreamWriter(fs,Encoding.UTF8);
sw.WriteLine(str);
sw.Flush();
sw.close();
fs.close();
读文件
var txtPath = "C:\\txt.txt";
FileStream fs;
StreamReader sr;
fs = new FileStream(txtPath,FileMode.Open,FileAccess.Read);
sr = new StreamReader(fs,Encoding.UTF8);
var str =sr.ReadToEnd();
sr.Close();
fs.Close();