C# StreamReader 标记问题
我想做的是记住我在输入流中的位置,然后再返回那里。 在java中使用mark()和reset()非常简单,但我不知道如何在c#中实现这一点。没有这样的方法。
例如
public int peek()
{
try
{
file.x; //in java file.mark(1)
int tmp = file.read();
file.+ //in java file.reset();
return tmp;
}
catch (IOException ex) {}
return 0;
}
What I am trying to do is remember where I am in an input stream and later go back there.
It is very simple in java using mark() and reset(), but I do not know how to make possible this in c#. There is no such method.
for example
public int peek()
{
try
{
file.x; //in java file.mark(1)
int tmp = file.read();
file.+ //in java file.reset();
return tmp;
}
catch (IOException ex) {}
return 0;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
据我所知确实没有。但是,您可以使用类似 Stack 的东西,然后简单地使用 Push() 和 Pop() 来按顺序上下移动标记:
基于字典的另一个想法:
Indeed there isn't that I know of. However you could use something like a Stack and simply Push() and Pop() off this to go up and down your markers in order:
Another idea based on a Dictionary:
如果您使用的是
StreamReader
,则必须记住,它本身并不完全是Stream
,但您可以访问其BaseStream
> 属性:它将为您提供您在流中的当前位置:
并且允许您移回到那里:
If it is a
StreamReader
you are using, you have to keep in mind that it is not exactly aStream
itself, but you can access itsBaseStream
property:It will give you your current position in the stream:
And it will allow you to move back there: