How to append text to a file in golang? [duplicate]

匿名 (未验证) 提交于 2019-12-03 08:36:05

问题:

This question already has an answer here:

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:

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()



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