只读txt文件中最后给定的x行 [英] read only given last x lines in txt file
本文介绍了只读txt文件中最后给定的x行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当前,我正在使用File.ReadAllText()读取文件内容,但是现在我需要读取txt文件中的最后x行.我该怎么办?
Currently I'm reading file content using File.ReadAllText(), but now I need to read last x lines in my txt file. How can I do that?
myfile.txt
content of myfile.txt
line1content
line2content
line3content
line4content
string contentOfLastTwoLines = ...
推荐答案
这怎么办
List <string> text = File.ReadLines("file.txt").Reverse().Take(2).ToList()
这篇关于只读txt文件中最后给定的x行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文