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:dotNetStudy1.txt";
StreamReader sr = new StreamReader(filePathr, Encoding.Default);
while (!sr.EndOfStream)
{
Console.WriteLine(sr.ReadLine());
}
Console.ReadKey();
string filePathw = @"E:dotNetStudy2.txt";
string ss = "今天天气真好,花儿都开了!";
using (StreamWriter sw = new StreamWriter(filePathw, false, Encoding.Default))
{
sw.Write(ss);
Console.WriteLine("写入成功!");
}
Console.ReadKey();
}
}
}