namespace Demo {
class Program {
static void Main(string[] args) {
//使用StreamReader来读取一个文本文件
using (StreamReader sr = new StreamReader(@"C:\Users\22053\Desktop\new.txt", Encoding.Default)) {
while (!sr.EndOfStream) {
Console.WriteLine(sr.ReadLine());
}
}
Console.ReadKey();
}
}
}
详情请参考官方文档
namespace Demo {
class Program {
static void Main(string[] args) {
//使用StreamWriter来写入一个文本文件
using (StreamWriter sw = new StreamWriter(@"C:\Users\22053\Desktop\a.txt", true)) {
sw.Write("看我把你覆盖掉");
}
Console.WriteLine("OK");
Console.ReadKey();
}
}
}
详情请参考官方文档
原文:https://www.cnblogs.com/lz32158/p/12920318.html