function - os.O_TRUNC 是做什么的?
问题描述
func OpenFile(name string, flag int, perm FileMode) (*File, error)
f, err := os.OpenFile("notes.txt", os.O_RDWR|os.O_CREATE|O_TRUNC, 0755)
“O_TRUNC”在写入之前是否清空整个文件?“截断”是什么意思?
此外,该函数是否ioutil.WriteFile()
在写入之前清空整个文件?
解决方案
os.O_TRUNC
以前对“如果可能”使用措辞的定义存在一些混淆- 请参见此处。
今天,文档阅读:
O_TRUNC int = syscall.O_TRUNC // truncate regular writable file when opened.
所以
“O_TRUNC”在写入之前是否清空整个文件?
是的。它本质上破坏了文件的内容 - 如果文件路径已经存在(并且是一个文件或指向现有文件的符号链接)。
同样来自ioutil.WriteFile 文档:
... WriteFile 在写入之前将其截断。
推荐阅读
- asp.net - NuGet 退出并显示代码 -1073741502 - .Net 构建失败
- terraform - 如何从 terraform 模块调用自定义 terraform 提供程序
- git - 如何将 MLfLow 与私有 git 存储库一起使用?
- react-native - 向后滑动时可以看到抽屉
- animation - 这是什么类型的图表,我们如何创建它?这是我们可以在 Python 中做的事情吗?
- gremlin - 已经遍历的过滤器路径
- c++ - 如果两个线程调用同一个函数,但是函数中的所有变量都是局部变量,我还需要担心线程之间共享数据吗?
- java - Spring JPA Criteria Builder 特定列
- php - DataTables 警告:table id=table-timsheet - Ajax 错误。有关此错误的更多信息,请参阅 http://datatables.net/tn/7
- python-3.x - 将 attr 与 src 布局一起使用时出现 ModuleNotFoundError