C
C
CityzenUNDEAD2022-03-07 18:33:45
.NET
CityzenUNDEAD, 2022-03-07 18:33:45

What exactly does the FileStream.Flush() method do?

Good evening!
Can anyone explain in a simpler way what this FileStream.Flush() method does?
Well, it kind of clears data from the buffer and writes it to disk, but what kind of data does it clear?
The data that I want to write is usually in an array of bytes, and they only get into the FileStream when I call the Write method, I don’t understand what it clears there.
And most importantly, where does he write them down? The documentation indicates what is on the disk, but damn, but where exactly in which file?
Sorry, but the example that is on msdn is somehow overloaded, it's not clear at all.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
G
GavriKos, 2022-03-07
@CityzenUNDEAD

When you write to a file stream (that is, you do a Write), the data does not immediately go to the file system (that is, to the file that you specified when creating the stream). Flush actually says "I'm done, you can write it all to hard". It actually clears exactly those internal buffer resources in which data was stored between write and FS. It's all hidden from the programmer, and in fact that's the point of the framework - you don't have to think about it.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question