文件流
时间:2011-01-27 来源:fjly.Mr.LEo^
1、创建一个文件流、指定路径与打开方式。
2、创建一个读取器,指定读取的文件流
3、读取文件中的所有内容
4、关闭读取器
5、关闭文件流
private void btnRead_Click(object sender, EventArgs e)
{
string path = txtFilePath.Text;
string content;
if (path.Equals(null) || path.Equals(""))
{
MessageBox.Show("文件路径不能为空");
return;
}
try
{
////创建文件流
//FileStream myfs = new FileStream(path, FileMode.Open, FileAccess.Read);
////创建读取器
//StreamReader mySr = new StreamReader(myfs);
////读取文件所有内容
//content = mySr.ReadToEnd();
//txtContent.Text = content;
////关闭读取器
//mySr.Close();
////关闭文件流
//myfs.Close();
//直接读取方式
StreamReader mySr = new StreamReader(path);
content = mySr.ReadToEnd();
txtContent.Text = content;
mySr.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message.ToString();
}
}

<img preview="http://pic.pdowncc.com/uploadimg/ico/2025/0523/1747993424374100.png" width="32" height="32" src="http://pic.pdowncc.com/uploadimg/ico/2025/0523/1747993424374100.png" alt="弓箭勇者最新版" />
飞行射击 下载
<img preview="http://pic.pdowncc.com/uploadimg/ico/2025/0523/1747993424374100.png" width="32" height="32" src="http://pic.pdowncc.com/uploadimg/ico/2025/0523/1747993424374100.png" alt="弓箭勇者最新版" />
飞行射击 下载
<img preview="http://pic.pdowncc.com/uploadimg/ico/2025/0523/1747993424374100.png" width="32" height="32" src="http://pic.pdowncc.com/uploadimg/ico/2025/0523/1747993424374100.png" alt="弓箭勇者最新版" />
飞行射击 下载- 4 <img preview="http://pic.pdowncc.com/uploadimg/ico/2025/0523/1747993424374100.png" width="32" height="32" src="http://pic.pdowncc.com/uploadimg/ico/2025/0523/1747993424374100.png" alt="弓箭勇者最新版" />下载73.78MB · 92℃
1970-01-01
- 5 <img preview="http://pic.pdowncc.com/uploadimg/ico/2025/0523/1747993424374100.png" width="32" height="32" src="http://pic.pdowncc.com/uploadimg/ico/2025/0523/1747993424374100.png" alt="弓箭勇者最新版" />下载43.7 MB · 90℃
1970-01-01
- 6 <img preview="http://pic.pdowncc.com/uploadimg/ico/2025/0523/1747993424374100.png" width="32" height="32" src="http://pic.pdowncc.com/uploadimg/ico/2025/0523/1747993424374100.png" alt="弓箭勇者最新版" />下载110.69MB · 92℃
1970-01-01