Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# StreamWriter - When is stream physically written to file?

Tags:

c#

In my app, I'm using a StreamWriter to stream data to a file. Are any bytes actually written to the file before the Close() method is called? If the answer is no, is this true no matter how large the stream is?

Randy

like image 386
Randy Minder Avatar asked Jan 04 '10 19:01

Randy Minder


1 Answers

The StreamWriter has an internal buffer, and once that buffer is full, it will get flushed to disk. You can force it to flush to disk at any time by calling Flush()

You can specify how big of a buffer you want in the constructors of StreamWriters if you wish.

like image 158
Matt Greer Avatar answered Sep 30 '22 01:09

Matt Greer