File.WriteAllText not flushing data to disk

只愿长相守 提交于 2019-11-29 09:44:31

You can use FileStream.Flush to force the data to disk. Write to a temp file and use File.Replace to atomically replace the target file.

I believe this is guaranteed to work. File systems give weak guarantees. These guarantees are hardly ever documented and they are complex.

Alternatively, you can use Transactional NTFS if available. It is available for .NET.

FileOptions.WriteThrough can replace Flush but you still need the temp file if your data can exceed a single cluster in size.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!