c# 记取txt 函数
public static 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;
}
{
// 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;
}
免责声明:本站所有资源均由网络搜集用户投稿而来,若有侵权,违法违规侵权内容请联系本站并提供必要证明,本站将及时删除违法违规内容,谢谢合作!