如何有效地仅读取文本文件的最后一行 [英] How to efficiently read only last line of the text file

查看:144
本文介绍了如何有效地仅读取文本文件的最后一行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

需要从大的日志文件只是最后一行。什么是做到这一点的最好方法是什么?

Need to get just last line from big log file. What is the best way to do that?

推荐答案

您想读取文件向后使用 ReverseLineReader

You want to read the file backwards using ReverseLineReader:

如何读取文本文件反向在C#

然后运行<$ C $迭代器。C>。取(1)它

var lines = new ReverseLineReader(filename);
var last = lines.Take(1);

您需要使用的乔恩斯基特的 MiscUtil ,而不是直接复制/粘贴代码。

You'll want to use Jon Skeet's library MiscUtil directly rather than copying/pasting the code.

这篇关于如何有效地仅读取文本文件的最后一行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆