In C++ it is possible to write buffered i/o using setvbuf. how to achieve the same in C#. Is there any method available to write buffered i/o in C#
How to write data to buffer before writing on to disk in C#
2.8k views Asked by sirisha At
2
There are 2 answers
0
On
Both FileStream and StreamWriter are internally buffered (they have a default buffer size of 4096 and 1024 bytes and constructors able to modify it).
The complex question would be how to write to a file without using a buffer :-) And note that, thanks to how they work, a StreamWriter that writes to a file will be double-buffered (the buffer of StreamWriter is independent of the one of FileStream). At least StreamWriter has an AutoFlush property that, when set to true, will flush after each write.
As already commented there is a BufferedStream class
Example code from MSDN:
Server side:
Client side: