【发布时间】:2019-07-10 05:03:55
【问题描述】:
我们知道像 FileStream 这样的后备存储流专门处理字节,因此我们需要流适配器来包装后备存储流。
假设我们使用 StreamReader:
// the data.txt only contains 3 chars in one line
using (StreamReader r = File.OpenText("data.txt"))
{
string input = null;
while ((input = r.ReadLine()) != null)
{
...
}
}
我可以说即使 StreamReader r 只发出 ReadLine() 一次,底层有一个 FileStream xxx(由 StreamReader 包装)发出 ReadByte() 3 次?
【问题讨论】:
-
您可以通过reading the code 准确了解它的工作原理。 ReadBuffer() 在这里。
-
@John 感谢您的链接,但我不是高级开发人员,您能告诉我,就我而言,StreamReader 的 ReadLine() 是否会触发多个 FileStream 的 ReadByte()?跨度>
-
不,它没有。
-
@John 你能看看这个问题吗? stackoverflow.com/questions/57050919/…