1 //StreamRead来读取一个文件 2 using (StreamReader sr = new StreamReader(@"C:UsersenleDesktop新建文本文档.txt", Encoding.Default)) 3 { 4 while (!sr.EndOfStream)//循环的去读文件 5 { 6 Console.WriteLine(sr.ReadLine()); 7 } 8 } 9 Console.ReadKey();
StreamWriter写入一个文本文件
//StreamWriter写入一个文本文件 using (StreamWriter strw = new StreamWriter(@"C:UserswbrmDesktop新建.txt",true ))//true 表示追加 { //strw.Write("别再能吃苦的年纪选择安逸"); strw.Write("看我有某有把你覆盖掉"); } Console.WriteLine("写入成功"); Console.ReadKey();