Does binarywriter.flush() also flush the underlying filestream object?

Posted by jacob sebastian on Stack Overflow See other posts from Stack Overflow or by jacob sebastian
Published on 2010-06-01T16:47:00Z Indexed on 2010/06/01 16:53 UTC
Read the original article Hit count: 440

Filed under:
|
|
|
|

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?

© Stack Overflow or respective owner

Related posts about c#

Related posts about .NET