BinaryWriter.Write

  • Thread starter Thread starter Boris
  • Start date Start date
B

Boris

// Example
BinaryWriter bw = new BinaryWriter(new
FileStream("c:\Test.bin",FileMode.Append));

BinaryWriter.Write writes data to the stream. However, it doesn't
automatically flush data any buffered data to the underlying device. What
determines *when* data is written to the underlying device, without calling
Flush function.

Thank you,
-Boris
 
It is determined by the size of the internal buffer (I believe you can
modifiy its size).
Also the writer flushes if the file is closed. To ensure that files are
always closed use the using statement:

using (BinaryWriter bw = new BinaryWriter(new
FileStream("c:\Test.bin",FileMode.Append)))
{
// do stuff with file here
}
// file is automatically closed
 
Boris said:
Do you have an example on how to change size of internal buffer?

Many of the FileStream constructors have a buffer size parameter. (The
BinaryWriter itself doesn't have a buffer, as far as I know.)
 
What is the default buffer size for FileStream?


Jon Skeet said:
Many of the FileStream constructors have a buffer size parameter. (The
BinaryWriter itself doesn't have a buffer, as far as I know.)
 
Boris said:
What is the default buffer size for FileStream?

That depends on what constructor is called. The docs specify for each
constructor. I think they're all 4K or 8K.
 
Back
Top