本文介绍了读取文本文件,自下而上?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有制表符分隔的文本文件,每天通过

自动化流程填充。新条目写在底部。我需要创建一个

实用程序,它使用最近的10个条目制作这个文件的副本。


当我使用StreamReader对象读取行时,它从顶部,所以

循环虽然线和跟踪线是没有用的。还有

无论如何从底部开始阅读,或者如果有人可以建议其他的

方式???


谢谢

I have tab delimited text file which gets populated on daily basis via
automated process. New entry is written at the bottom. I need to create a
utility which makes a copy of this file with 10 most recent entries.

When I read line using StreamReader object it starts from the top, so
looping though lines and keeping track of the line is not helpful. Is there
anyway to start reading from the bottom or if anyone could suggest some other
way???

Thanks

推荐答案




从结尾处阅读文件在一般情况下非常困难,

部分是因为你必须继续向你读取的每个

字节寻求倒退,否则你必须保持一个缓冲区并读取(比如说)最后的
10个字节,然后在此之前寻找10个字节的开头等等。


然后你有字符编码的附加问题 - 如果你使用的是固定宽度的字符编码,那就不是很糟糕了,但是

就像UTF-8 ,你必须找出

前一个角色的起点,等等。


-

Jon Skeet - < sk *** @ pobox.com>


如果回复群组,请不要给我发邮件



Reading from the end of a file is very difficult in a general case,
partly because you''d have to keep either seeking backwards for every
byte you read, or you''d have to keep a buffer and read (say) the last
10 bytes, then seek to the start of the 10 bytes before that, etc.

You then have the added problem of character encodings - it''s not so
bad if you''re using a fixed-width character encoding, but with
something like UTF-8, you have to work out where the start of the
previous character is, etc.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too




这篇关于读取文本文件,自下而上?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 07:46
查看更多