我如何处理“流不可读” [英] How Do I Handle "Stream Was Not Readable"

查看:263
本文介绍了我如何处理“流不可读”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好!

我创建了一个file.txt。我可以在文件中写一次,但是当我尝试在下面的行之后读取文件时

使用(StreamReader Sread = new StreamReader(Filestream))



i成为一个错误:流不可读。



我该如何处理这个错误?

Hello everyone!
i create a file.txt. i could write once in the file but when i am trying to read in the file just after the following line
using (StreamReader Sread = new StreamReader(Filestream))

i become an error: "Stream was not readable".

please how can i handle this error?

推荐答案

只是这一行并没有帮助我们把它放在上下文中来弄清楚你还在做什么。

所以上面的代码 - 你说的那样您可以在文件中写一次 - 也可能是相关的。



猜测,您正在尝试重用用于编写文件的文件流,这可能是问题的原因。如果流是从写入开放的,您可能无法通过单独的StreamReader重复读取它!
Just that line doesn't help us put it in context to work out what else you may be doing.
So the code above that line - you say that "you can write once in the file" - may be relevant as well.

At a guess, you are trying to reuse the file stream that you used for writing the file, and that is probably the cause of the problem. If the stream is open from writing, you probably can't reuse it for reading via a separate StreamReader!


这篇关于我如何处理“流不可读”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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