读取文本文件,自下而上? [英] Reading text file, bottom up?

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

问题描述

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

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

实用程序,它使用最近的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

推荐答案

工作批次< Jo **** @ discussion.microsoft.com>写道:
Job Lot <Jo****@discussions.microsoft.com> wrote:
我有制表符分隔的文本文件,每天通过
自动化过程填充。新条目写在底部。我需要创建一个
实用程序,它使用最近的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???




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

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

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


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

就像UTF-8 ,你必须找出

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


-

Jon Skeet - < sk *** @ pobox.com>
http:// www。 pobox.com/~skeet

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



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

也许这会有所帮助:
http://dotnetjunkies.com/WebLog/john.../05/41694.aspx


-

--- Nick Malik [微软]

MCSD,CFPS,认证Scrummaster
http://blogs.msdn.com/nickmalik


免责声明:本论坛中发表的意见均为我自己的意见,而不是

代表我的雇主。

我不代表我的雇主回答问题。我只是一个帮助程序员的
程序员。

-

" Job Lot" <乔**** @ discussions.microsoft.com>在消息中写道

news:72 ********************************** @ microsof t.com ...
perhaps this will help:
http://dotnetjunkies.com/WebLog/john.../05/41694.aspx

--
--- Nick Malik [Microsoft]
MCSD, CFPS, Certified Scrummaster
http://blogs.msdn.com/nickmalik

Disclaimer: Opinions expressed in this forum are my own, and not
representative of my employer.
I do not answer questions on behalf of my employer. I''m just a
programmer helping programmers.
--
"Job Lot" <Jo****@discussions.microsoft.com> wrote in message
news:72**********************************@microsof t.com...
我有制表符分隔的文本文件,每天通过自动化过程填充。新条目写在底部。我需要创建一个
实用程序,它使用最近的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



工作,


只是一个想法,


会在arraylist中读取它使用insert(0,line),当你每次第10行存在的时候删除

是个主意吗?


Cor
Job,

Just an idea,

Would reading it in an arraylist using insert(0,line), while you remove when
that exist everytime row 10 be an idea?

Cor


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

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