StreamReader和StreamWrite操作文件
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; namespace _04Stream读写文件 { class Program { static void Main(string[] args) { string filePathr = @"E:\dotNet\Study\1.txt"; StreamReader sr = new StreamReader(filePathr, Encoding.Default); while (!sr.EndOfStream) { Console.WriteLine(sr.ReadLine()); } Console.ReadKey(); string filePathw = @"E:\dotNet\Study\2.txt"; string ss = "今天天气真好,花儿都开了!"; using (StreamWriter sw = new StreamWriter(filePathw, false, Encoding.Default)) { sw.Write(ss); Console.WriteLine("写入成功!"); } Console.ReadKey(); } } }
原文:https://www.cnblogs.com/nymz/p/13826446.html