WPF读写文件:StreamReader 与 StreamWriter

1.读文件

1 StreamReader sr = new StreamReader(@"D:\JointIn.txt");
2 string sLine = "";
3 while(!sr.EndOfStream)
4 {
5        sLine += sr.ReadLine();
6 }
7 Console.WriteLine(sLine); 
8 sr.Close(); 

2.写文件

1 StreamWriter sw = new StreamWriter(@"D:\JointOut.txt");
2 sw.WriteLine("Hello World");
3 sw.Flush();
4 sw.Close();

 

posted @ 2022-09-09 15:17  LXLR  阅读(11)  评论(0编辑  收藏  举报