/// summary /// 逐行读取文件到泛型数组 /// /summary /// param name="FilePath"/param /// returns/returns private List string ReadFileToList( string FilePath) { // 新建文件流 FileStream fsRead; // 用FileStream文件流打开文
/// <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; }