Connecting Tech Pros Worldwide Forums | Help | Site Map

Re: When using System.IO.FileStream, I write 8 bytes, then seek to the start of the file, does the 8 bytes get flushed on seek and the buffer become a readbuffer at that point instead of being a write buffer?

Anthony Jones
Guest
 
Posts: n/a
#1: Jul 29 '08

"DR" <softwareengineer98037@yahoo.comwrote in message
news:OZoyDzR8IHA.1200@TK2MSFTNGP04.phx.gbl...
Quote:
When using System.IO.FileStream, I write 8 bytes, then seek to the start
of
Quote:
the file, does the 8 bytes get flushed on seek and the buffer become a
readbuffer at that point instead of being a write buffer?
>
>
A simple experiment in .NET 2.0 and Windows XP shows that it does appear to
flush on the seek.

However whether you should rely in that behaviour depends on why you asked
the question. If you are worried that you might be overwritting data that
hasn't been stored yet then don't be.

If you want to make sure that data is persisted before doing other things
then you should explicitly flush. Just because seek appears to flush in a
the above case may simply be a result of specific OS decisions. In other
circumstances the underlying OS (on windows FileStream is a fairly
transparent wrapper on the Win APIs for these operations) may make other
choices.

--
Anthony Jones - MVP ASP/ASP.NET



Closed Thread