Delete the first line of the text file without reading it.

I am working with a very large text file (about 70 thousand lines) and I want to delete the top line.

Clearly, load the whole thing into memory by deleting the top line, and then re-writing all of this is ineffective:

var lines = File.ReadLines(accountFileLocation.Text).Skip(1); File.WriteAllLines("output.txt", lines); 

Is there any other way to do this?

+6
source share
1 answer

Hehe ... finally I can say Jon Skeet said :)

John Skeet said : not really

What you have done is one approach. The second one will have to open the read stream and the write stream (to another file) and read the line, and then write it to the record if you want (more for โ€œtest lines for reliabilityโ€ than for all but the first line).

So ... it looks like you got the right answer ...

+1
source

Source: https://habr.com/ru/post/958043/


All Articles