StreamReader 读取Txt文件
Code
1 string filePath = @Environment.CurrentDirectory + "\\SimuAppClient.txt";
2 if(!File.Exists(filePath))
3 {
4 return;
5 }
6 var filest = new FileStream(filePath, FileMode.Open, FileAccess.ReadWrite);
7 using (var sr = new StreamReader(filest))
8 {
9 string strLine = sr.ReadLine(); //读取文件中的一行
10 while (strLine != null) //判断是否为空,表示到文件最后一行了
11 {
12 txtRead.AppendText(strLine
13 +"\r"); //自动换行
14 strLine = sr.ReadLine();
15 }
16 sr.Close(); //关闭流
17 filest.Close();
18 }
转载于//www.cnblogs.com/w2011/archive/2012/10/11/2719683.html
还没有评论,来说两句吧...