Alex Rivera | Logout

Close a filestream without Flush()

Asked 2011-09-11T07:43:40.760
30

Can I close a file stream without calling Flush (in C#)? I understood that Close and Dispose calls the Flush method first.

Edit
Report

1 Answer

-1

Wrap the FileStream in a BufferedStream and close the filestream before the buffered stream.

var fs = new FileStream(...);
var bs = new BufferedStream(fs, buffersize);

bs.Write(datatosend, 0, length);

fs.Close();
try {
    bs.Close();
}
catch (IOException) {
}
answered 2011-09-11T09:16:15.730

Your Answer