-1

I want to remember where, that my program had processed. I call StreamReader ReadLine()

Then next time I can jump right back to the location keep processing.

I don't want to do the line count and skip, I want to store a physicial location or something like that. So next time I can jump right back.

Thanks

Benny Ae
  • 1,897
  • 7
  • 25
  • 37

1 Answers1

0

you can count your text length, and then seek it before reading like below code: hope it can help you.

internal class Program
    {
        static void Main(string[] args)
        {
            var fileName = "your file path";
            long count = 0;
            var firstLine = GetContent(fileName, count);
            count += firstLine.position;
            var secondLine = GetContent(fileName, count);
            count += secondLine.position;
            var thirdLine = GetContent(fileName, count);
        }

        public static (string content, int position) GetContent(string fileName, long position)
        {
            using var x = File.OpenRead(fileName);
            using var ww = new StreamReader(x);
            x.Seek(position, SeekOrigin.Begin);
            var k = ww.ReadLine();
            return (k, ww.CurrentEncoding.GetByteCount(k) + 2); 
        }
    }
miemengniao
  • 592
  • 2
  • 11