C#操作文本读写流--- StreamWritter and StreamReader

发布时间:2009年06月04日      浏览次数:634 次
.Net 为我们对流进行了封装,所以在我们用c#进行流操作时,可以直接使用封装好的高级流StreamWritter and StreamReader来进行文本的读写操作,不用再用二进制进行文本的读写操作,这样方便快捷,但是运用二进制进行文本操作是永远可行的,毕竟文本流的本质就是二进制流。 using System;
using System.Collections.Generic;
using System.Text;
using System.IO; //Stream操作必须要添加的域名空间
namespace Stream
{
class Program
{
static void Main(string[] args)
{
string path = @"E:StreamText.txt";
StreamManipulation.Write(path);
StreamManipulation.Read(path);
}
}
class StreamManipulation
{
public static void Write(string path)
{
StreamWriter sw = new StreamWriter(path, false);
sw.WriteLine("Welcome to the stream world!");
sw.WriteLine("Come On!");
sw.Close();
}
public static void Read(string path)
{
StreamReader sr = new StreamReader(path);
string s;
while (!sr.EndOfStream)
{
s = sr.ReadLine();
Console.WriteLine(s);
}
Console.Read();
}
}
}
免责声明:本站相关技术文章信息部分来自网络,目的主要是传播更多信息,如果您认为本站的某些信息侵犯了您的版权,请与我们联系,我们会即时妥善的处理,谢谢合作!