重绕TextReader文件流。 [英] Rewinding a TextReader file stream.

查看:67
本文介绍了重绕TextReader文件流。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

如何回放以下静音流:


TextReader tr = new StreamReader(File.Open(fileName,FileMode.Open) ));


是否有专门的方法或者我应该关闭并重新打开文件...

非常感谢,


Alberto

解决方案

使用FileStream,它支持通过Seek方法进行随机访问:

http:// msdn2。 microsoft.com/en-us/lib...ilestream.aspx


-

HTH,

Kevin Spencer

Microsoft MVP

Chicken Salad Shooter
http://unclechutney.blogspot.com

男人,计划,运河,回文都有...哦,没关系。


< in ** @ devdept.comwrote in message

新闻: 11*********************@b28g2000cwb.googlegro ups.com ...


大家好,


如何回放以下静默流:


TextReader tr = new StreamReader(File.Open(fileName,FileMode.Open) );


是否有专门的方法或者我应该关闭并重新打开文件...


非常感谢,


Alberto



Kevin Spencer< sp ** @ uce.govwrote:


使用FileStream,它支持通过Seek方法进行随机访问:

http://msdn2.microsoft.com/en-us/lib...ilestream.aspx



但要注意,如果你在FileStream中寻找,你需要在StreamReader上调用

DiscardBufferedData(),否则它会继续给予

缓冲再次从流中读取数据。


-

Jon Skeet - < sk *** @ pobox.com>
http://www.pobox.com/~skeet 博客: http://www.msmvps.com/jon.skeet

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


谢谢大家,

你能不能给我一个小的speudocode例子打开一个文件

文件/从中读取/快退/再次阅读?

谢谢,


Alberto


Hi All,
How can i rewind the following sile stream:

TextReader tr = new StreamReader(File.Open(fileName, FileMode.Open));

Is there a dedicated method or shall I close and re-open the file...
Thanks a lot,

Alberto

解决方案

Use a FileStream, which supports random access via the Seek method:

http://msdn2.microsoft.com/en-us/lib...ilestream.aspx

--
HTH,

Kevin Spencer
Microsoft MVP
Chicken Salad Shooter
http://unclechutney.blogspot.com

A man, a plan, a canal, a palindrome that has.. oh, never mind.

<in**@devdept.comwrote in message
news:11*********************@b28g2000cwb.googlegro ups.com...

Hi All,
How can i rewind the following sile stream:

TextReader tr = new StreamReader(File.Open(fileName, FileMode.Open));

Is there a dedicated method or shall I close and re-open the file...
Thanks a lot,

Alberto



Kevin Spencer <sp**@uce.govwrote:

Use a FileStream, which supports random access via the Seek method:

http://msdn2.microsoft.com/en-us/lib...ilestream.aspx

But beware that if you seek within the FileStream, you''ll need to call
DiscardBufferedData() on the StreamReader, otherwise it''ll keep giving
buffered data before reading from the stream again.

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


Thanks guys,
Can you please provide me a small speudocode example of opening a text
file/reading from it/rewind it/read again?
Thanks,

Alberto


这篇关于重绕TextReader文件流。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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