您的位置:首页 > 其它

StreamReader和StreamWriter(字符)

2016-02-24 20:58 471 查看
StreamReader和StreamWriter用于操作文本文件

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
//使用StreamReader来读取一个文本文件
using (StreamReader sr = new StreamReader(@"C:\Users\SpringRain\Desktop\抽象类特点.txt", Encoding.Default))
{
while (!sr.EndOfStream)
{
Console.WriteLine(sr.ReadLine());
}
}

//使用StreamWriter来写入一个文本文件
using (StreamWriter sw = new StreamWriter(@"C:\Users\SpringRain\Desktop\newnew.txt", true))
{
sw.Write("看我有木有把你覆盖掉");
}
Console.WriteLine("OK");
Console.ReadKey();
}
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: