开发者

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

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 a开发者_如何转开发nswer is no, is this true no matter how large the stream is?

Randy


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.


Stream is written by StreamWriter.Flush.


It depends on the underlying stream that is being used, the size of the buffer in that stream and other factors.

You can force a write to the underlying stream by calling flush() on your StreamWriter.

I assume from your question that you are using a file stream underneath. In my experience the flush generally occurs between every 1-4K of data, but I am not sure what the exact point is.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜