0

ストリーミングしているファイルのサイズが非常に大きくなる可能性があるため、1mb から 2gb までのさまざまなサイズのファイルを読み取る必要があります。

  • ファイルのどのくらいが読み取られたかを知り、すべての行を事前に読み取らずにそれを追跡するにはどうすればよいですか?

サンプルコード

int count = 0;
using (Stream stream = File.OpenRead(filename))
{
    using (StreamReader reader = new StreamReader(stream))
    {
        string item = string.Empty;
        while ((item = reader.ReadLine()) != null)
        {
            item = item.Replace("\"", ""); // remove unwanted double quotes
            if (item.Length < 2) // dont need lines with less then 2 char
                continue;

            if (fine add to db) 
                count++; // to keep track of good lines
        }
    }
}
4

2 に答える 2

0
var remaining = yourFile.Length;
var goodLines = File.ReadLines(yourFile.FullName)
                    .Select(line => line.Replace("\"", ""))
                    .Where(line => line.Length > 1);

foreach(var goodLine in goodLines)
{
   // do something with goodLine

   // this will be slightly off since you remove quotes.
   remaining -= (goodLine.Length + Environment.NewLine.Length);
}

MSDN File.ReadLines

于 2012-11-11T21:45:47.560 に答える
0

クラスから"Position"オーバーライドされるプロパティを使用する必要があります。"FileStream""Stream"

こちらをご覧ください

于 2012-11-11T21:18:50.723 に答える