c#操作文本文件
2006-03-13 14:21
351 查看
using System.IO;
//声明控件
protected System.Web.UI.HtmlControls.HtmlTextArea txtValue;
读取文本文件:
//主程序
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();
//声明控件
protected System.Web.UI.HtmlControls.HtmlTextArea txtValue;
读取文本文件:
//主程序
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();
相关文章推荐
- C#操作文本文件 在行首和行尾追加文本
- C#操作文本文件
- c#操作文本文件
- C# 文本文件操作 IO流
- C#文本文件的操作
- 文本文件操作(C#)
- C#操作文本文件
- c#中读写ini文件(C#操作文本文件、C#读写文本文件)
- c# 中读写ini文件(C#操作文本文件、C#读写文本文件)
- C#文本文件操作
- c#操作文本文件或日志文件封装类
- C#文本文件的操作
- C#创建创建文本文件写入读取,可以用来做系统日志或程序操作日志或者错误记录
- c# 流的概念以及一个操作文本文件的实例代码
- 在c#中如何操作文本文件
- C# 文本文件操作 IO流
- C#操作文本文件
- C#中基于FileStream的文本文件读写操作
- C#操作文本文件(.txt)[转]
- c#操作文本文件