现在的位置: 首页 > 综合 > 正文

C#文本文件的操作

2014年01月24日 ⁄ 综合 ⁄ 共 603字 ⁄ 字号 评论关闭

FileStream fsInfo = new FileStream( "文件路径(在项目内的)", FileMode.Open, FileAccess.Read );
StreamReader srInfo = new StreamReader( fsInfo, System.Text. Encoding.GetEncoding( "GB2312" ) );
srInfo.BaseStream.Seek( 0, SeekOrigin.Begin );
txtValue.Value = " ";
string strLine = srInfo.ReadInfo();
while( strLine != null )
{
txtValue.Value += strLine + "/n";
strLine = srInfo.ReadLine();
}
srInfo.Close();

写入文本文件:

//主程序
FileStream fsInfo = new FileStream( 文件路径(在项目内的)", FileMode.OpenOrCreate, FileAccess.Write );
StreamWriter swInfo = new StreamWriter( fsInfo );
swInfo.Flush();
swInfo.BaseStream.Seek( 0, SeekOrigin.Begin );
swInfo.Write( txtValue.Value );

swInfo.Flush();
swInfo.Close();

抱歉!评论已关闭.