Close a filestream without Flush()

后端 未结 7 2022
猫巷女王i
猫巷女王i 2021-01-03 20:42

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

相关标签:
7条回答
  • 2021-01-03 21:44

    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) {
    }
    
    0 讨论(0)
提交回复
热议问题