gpt4 book ai didi

c# - binarywriter.flush() 是否也刷新底层文件流对象?

转载 作者:行者123 更新时间:2023-11-30 15:48:06 24 4
gpt4 key购买 nike

我有一段代码如下:

Dim fstream = new filestream(some file here)
dim bwriter = new binarywriter(fstream)
while not end of file
read from source file
bwriter.write()
bwriter.flush()
end while

我的问题如下。当我调用 bwriter.flush() 时,它是否也会刷新 fstream 对象?或者我是否必须显式调用 fstream.flush(),如下例所示:

while not end of file
read from source file
bwriter.write()
bwriter.flush()
fstream.flush()
end while

一些人建议我需要显式调用 fstream.flush() 以确保将数据写入磁盘(或设备)。但是,我的测试表明,一旦我在 bwriter 对象上调用 flush() 方法,数据就会立即写入磁盘。

有人可以证实这一点吗?

最佳答案

根据 Reflector,BinaryWriter.Flush调用底层流的 Flush 方法。

关于c# - binarywriter.flush() 是否也刷新底层文件流对象?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2951638/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com