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

发布于 2024-09-04 11:55:16 字数 588 浏览 8 评论 0原文

我有一个代码片段如下:

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 对象上调用lush() 方法,数据就会写入磁盘。

有人可以证实这一点吗?

I have got a code snippet as follows:

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

The question I have is the following. When I call bwriter.flush() does it also flush the fstream object? Or should I have to explicitly call fstream.flush() such as given in the following example:

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

A few people suggested that I need to call fstream.flush() explicitly to make sure that the data is written to the disk (or the device). However, my testing shows that the data is written to the disk as soon as I call flush() method on the bwriter object.

Can some one confirm this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

指尖上的星空 2024-09-11 11:55:16

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

According to Reflector, BinaryWriter.Flush calls the Flush method of the underlying stream.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文