【发布时间】:2016-12-14 19:12:25
【问题描述】:
我想读取每一行格式的 txt 文件。而不是每一行,我得到每隔一行。问题是我为什么以及如何做一些事情。 列表.txt: 60001 60002 60003 60004 ..单行中的每个数字等100行
StreamReader podz = new StreamReader(@"D:\list.txt");
string pd="";
int count=0;
while ((pd = podz.ReadLine()) != null)
{
Console.WriteLine("\n number: {0}", podz.ReadLine());
count++;
}
Console.WriteLine("\n c {0}", count);
Console.ReadLine();
【问题讨论】:
-
使用
pd而不是 readline 进入 pd,然后 readline。您的代码当前 readlines 到 pd,忽略它和 readlines - 每次循环迭代 2 个 readlines -
为什么不直接使用
File.ReadAllLines(string path)? MSDN。然后你可以只做foreach (string line in lines),这样你甚至不需要int count,因为你有lines.Count。
标签: c# streamreader readline