您需要添加
O_WRONLY标志:
if f, err := os.OpenFile("./log.log", os.O_APPEND|os.O_WRONLY, os.ModeAppend); err != nil { }为了说明,这是Linux文档
open:http : //man7.org/linux/man-
pages/man2/openat.2.html:
参数标志必须包括以下访问模式之一:O_RDONLY,O_WRONLY或O_RDWR。这些请求分别打开文件为只读,只写或读/写。
如果检查/usr/local/go/src/syscall/zerrors_linux_amd64.go:660,则可以看到:
O_RDonLY = 0x0O_RDWR = 0x2O_WRonLY = 0x1
因此,默认情况下,您将获得一个只读文件描述符。



