首页 > 代码库 > c#读写txt

c#读写txt

附加到txt:StreamWrite sw =System.IO.File.AppendText(path); //绝对路径 sw.Write("写入内容");

写入到txt: StreamWrite sw2 =new StreamWrite(); sw.Write("写入内容");

最后都要 sw.Close();

读取txt:StreamReader sr = new StreamReader(path); //绝对路径   string line=""; while((line=sr.ReadLine())!=null){//操作行}  最后关闭流 sw.Close();

 

c#读写txt