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#文本文件的操作
最新推荐文章于 2025-09-06 13:04:52 发布
本文提供了一个使用C#进行文本文件读写的示例代码,包括如何打开文件、逐行读取内容、关闭文件流以及如何创建或打开文件并写入内容等关键步骤。
374

被折叠的 条评论
为什么被折叠?



