Why must I Close() a file in C#?

后端 未结 6 1515
自闭症患者
自闭症患者 2021-02-20 12:47

I know this might seem silly, but why does the following code only work if I Close() the file? If I don\'t close the file, the entire stream is not written.

Steps:

6条回答
  •  梦如初夏
    2021-02-20 13:27

    Operating system cache write to block devices to enable the OS to have better performance. You force a write by flushing the buffer after a write of setting the streamwriter to autoflush.

提交回复
热议问题