微软提供的StreamReader与StreamWriter,更加频繁的活动,例如“日志系统”
using System.IO;
class Demo(){
//声明路径文件
private string _strPate=@"E:\Test.txt";
///<summary>
///文本文件的写入
///</summary>
public void Write(){
string str="******&^^*^";
StreamWriter sw=new StreamWriter(_strPate);
sw.WritrLine(str);
sw.Close();
}
///<summary>
///文本文件的读取
///</summary>
public void Read(){
StreamReader sr=new StreamReader(_StrPath);
While(sr.Peek()>=0){ //Peek方法指针概念,大于零就说明里面有数据
Console.WriteLine(sr.ReadLine());
}
sr.Close();
}
static void Main(string[] args){
Demo obj=new Demo();
obj.Write();
obj.Read();
}
}