'go how to write append file by using ioutil [duplicate]
I try to use the following code
appendStr := []byte("append test")
ioutil.WriteFile("./test.txt", appendStr, os.ModeAppend)
but it seems does not work
Solution 1:[1]
As JimB already explained
appendStr := []byte("\n append test")
f, err := os.OpenFile("text.log", os.O_APPEND, 0666)
if err != nil {
fmt.Println(err)
return
}
defer f.Close()
n, err := f.Write(appendStr)
if err != nil {
fmt.Println(err)
return
}
fmt.Printf("wrote %d bytes\n", n)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Manjeet Thakur |
