如何在golang中将文本追加到文件中?

huangapple go评论90阅读模式
英文:

How to append text to a file in golang?

问题

我发现os.Open()返回一个O_RDONLY文件,os.Create()返回一个O_RDWR文件,但找不到一个方法返回一个APPEND文件指针。

有什么帮助吗?

英文:

I find os.Open() return a O_RDONLY file and os.Create() return a O_RDWR but can't find a method return a APPEND file pointer.

Any help ?

答案1

得分: 55

The OpenFile takes a flags argument that you can use:

 os.OpenFile("foo.txt", os.O_RDWR|os.O_APPEND, 0660);

Used with O_CREATE , OpenFile can also serve the same purpose as os.Create()

英文:

The OpenFile takes a flags argument that you can use:

 os.OpenFile("foo.txt", os.O_RDWR|os.O_APPEND, 0660);

Used with O_CREATE , OpenFile can also serve the same purpose as os.Create()

huangapple
  • 本文由 发表于 2012年11月22日 21:06:18
  • 转载请务必保留本文链接:https://go.coder-hub.com/13513375.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定