首页  编辑  

文本文件处理

Tags: /C#/文件目录操作/   Date Created:

using System . IO;

StreamReader vStreamReader = new StreamReader ( @"C:\temp\temp.txt", Encoding . Default);

string vText = "" ;

string vLine;

while ((vLine = vStreamReader . ReadLine()) != null )

{

   // TODO

   vText += vLine + "\r\n" ;

}

vStreamReader . Close();

StreamWriter vStreamWriter = new StreamWriter ( @"C:\temp\temp.txt" , false , Encoding . Default);

vStreamWriter . Write(vText);

vStreamWriter . Close();