Removing the first line of a text file in C#

Viewed 37905

I can currently remove the last line of a text file using:

    var lines = System.IO.File.ReadAllLines("test.txt");
    System.IO.File.WriteAllLines("test.txt", lines.Take(lines.Length - 1).ToArray());

Although, how is it possible to instead remove the beginning of the text file?

5 Answers

can do in one line also

File.WriteAllLines(origialFilePath,File.ReadAllLines(originalFilePath).Skip(1));

Assuming you are passing your filePath as parameter to the function.

Related