go 怎么追加写文件?
package main
import (
"bufio"
"fmt"
"os"
)
func main() {
filePath
:= "/etc/hosts"
file
, err
:= os
.OpenFile(filePath
, os
.O_WRONLY
|os
.O_APPEND
, 0666)
if err
!= nil {
fmt
.Println("文件打开失败", err
)
}
defer file
.Close()
write
:= bufio
.NewWriter(file
)
write
.WriteString("test \n")
write
.Flush()
}
转载请注明原文地址:https://tech.qufami.com/read-29321.html