码迷,mamicode.com
首页 > Windows程序 > 详细

C# 读取文本文件

时间:2014-11-19 12:05:01      阅读:191      评论:0      收藏:0      [点我收藏+]

标签:style   blog   io   ar   color   os   sp   文件   on   

 1 // get files
 2         private ErrorCode get_files(string profile)
 3         {
 4             ErrorCode err = ErrorCode.Err_None;
 5             FileStream fs = null;
 6             StreamReader sr = null;
 7             this.files = new ArrayList();
 8             try
 9             {
10                 fs = new FileStream(profile, FileMode.Open, FileAccess.Read);
11                 sr = new StreamReader(fs, System.Text.Encoding.Default);
12 
13                 string line;
14                 while ((line = sr.ReadLine()) != null)
15                 {
16                     if (File.Exists(line))
17                         this.files.Add(line);
18                 }
19             }
20             catch (Exception e)
21             {
22                 err = ErrorCode.Err_ReadProfile;
23             }
24             finally
25             {
26                 if (sr != null)
27                 {
28                     sr.Close();
29                     sr = null;
30                 }
31                 if (fs != null)
32                 {
33                     fs.Close();
34                     fs = null;
35                 }
36             }
37             return err;
38         }

 

C# 读取文本文件

标签:style   blog   io   ar   color   os   sp   文件   on   

原文地址:http://www.cnblogs.com/aoun/p/4107597.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!