Talk is cheap,show me the code!
/// <summary>读取文件,返回一个含有文件数据的行列表</summary>
/// <param name="TxtFilePath">文件路径</param>
/// <returns>文件数据的行列表</returns>
private List<string> ReadTxtFromFile(string TxtFilePath)
{
// 1 首先创建一个泛型为string 的List列表
List<string> AllRowStrList = new List<string>();
{
// 2 加载文件
System.IO.StreamReader sr = new
System.IO.StreamReader(TxtFilePath,
Encoding.Default);
String line; // 3 调用StreamReader的ReadLine()函数
while ((line = sr.ReadLine()) != null)
{ // 4 将每行添加到文件List中
AllRowStrList.Add(line);
}
// 5 关闭流
sr.Close();
}
// 6 完成操作
return AllRowStrList;
}