C# 读取文本文件

 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         }

 

你可能感兴趣的:(文本文件)