When to flush a file in Go?

前端 未结 4 933
离开以前
离开以前 2021-02-07 06:35

When is it necessary to flush a file?
I never do it because I call File.Close and I think that it is flushed automatically, isn\'t it?

4条回答
  •  南笙
    南笙 (楼主)
    2021-02-07 07:10

    See here. File.Sync() is syscall to fsync. You should be able to find more under that name.

    Keep in mind that fsync is not the same as fflush and is not executed before close.

    You generally don't need to call it. The file will be written to disk anyway, after some time and if there is no power failure during this period.

提交回复
热议问题