代码:
/****************************
*
* 纯文本文件的读写
* StreamReader,StreamWriter
*
* ***************************/
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
namespace 文件流技术
{
class Demo3
{
private string _StrAimPath = @"E:\TeacherLiuSutdy\Hight Level Teach\Test3.txt";
/// <summary>
/// 文本文件的写入
/// </summary>
public void Test1()
{
string str = "同学大家上午好";
StreamWriter sw = new StreamWriter(_StrAimPath);
sw.WriteLine(str);
sw.Close();
}
/// <summary>
/// 文本文件的读取
/// </summary>
public void Test2()
{
StreamReader sr = new StreamReader(_StrAimPath);
while (sr.Peek()>=0)
{
Console.WriteLine(sr.ReadLine());
}
sr.Close();
}
static void Main(string[] args)
{
Demo3 obj = new Demo3();
obj.Test1();
obj.Test2();
Console.ReadKey();
}
}
}