c#逐行读取文件到数组
/// <summary> /// 逐行读取文件到泛型数组 /// </summary> /// <param name="FilePath"></param> /// <returns></returns> private List<string> ReadFileToList(string FilePath) { //新建文件流 FileStream fsRead; //用FileStream文件流打开文件 try { fsRead = new FileStream(FilePath, FileMode.Open); } catch (Exception) { throw; } //"GB2312"用于显示中文字符,写其他的,中文会显示乱码 StreamReader reader = new StreamReader(fsRead, UnicodeEncoding.GetEncoding("GB2312")); List<string> list=new List<string>(); string search; while ((search=reader.ReadLine()) != null) { list.Add(search); } fsRead.Close(); return list; }
posted on 2019-09-09 16:10 Keepshining 阅读(1699) 评论(0) 收藏 举报
浙公网安备 33010602011771号