views:

53

answers:

1

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?

+1  A: 

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

dtb
Thank you dtb. That matches with the results of my testing as well. Thank you very much for taking time to verify this on reflector.
jacob sebastian