C#操作文本读写流--- StreamWritter and StreamReader
2007-07-09 11:17
507 查看
.Net 为我们对流进行了封装,所以在我们用c#进行流操作时,可以直接使用封装好的高级流StreamReader和StreamWritter来进行文本的读写操作,不用再用二进制进行文本的读写操作,这样方便快捷,但是运用二进制进行文本操作是永远可行的,毕竟文本流的本质就是二进制流。
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();
}
}
}
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();
}
}
}
相关文章推荐
- c#/.net 基于文件流FileStream读写的文本操作小程序
- unity3d C#文本读写操作
- c#操作excel方式一:stream简单读写excel
- c#操作excel方式一:stream简单读写excel
- c#/.net 基于文件流FileStream读写的文本操作小程序
- 30天C#基础巩固------读写流(StreamWrite/StreamReader)
- !!无须定义配置文件中的每个变量的读写操作,以下代码遍历界面中各个c#控件,自动记录其文本,作为配置文件保存
- c#操作excel方式一:stream简单读写excel
- c# 文件IO操作 StreamReader StreamWriter Split 使用
- C# FileStream读写的文本操作代码分析
- c# 文件IO操作 StreamReader StreamWriter Split 使用
- C# StreamReader文件处理操作解析
- C# 文件操作之 StreamReader & StreamWriter
- C#字符串操作 取文本左边 取文本右边 取文本中间 取文本中间到List集合 指定文本倒序
- C#对文件操作(基本的读写以及压缩和解压)
- C# StreamReader/StreamWriter与FileStream用法详解
- .Net那点事儿系列:C#操作Xml:通过XmlDocument读写Xml文档
- C#操作Excel(创建、打开、读写、保存)几种方法的总结
- C#操作Xml:通过XmlDocument读写Xml文档
- C#中npoi操作Excel[版本2.0.1读写2003、2007格式]