O_CREATE 创建
O_APPEND追加模式
O_TRUNC 写时清空
writer := bufio.NewWriter(file)
n,err := writer.WriteString(“fgm”)
package main
import (
"fmt"
"os"
)
func main() {
file,err = os.OpenFile("./hello.txt",os.O_CREATE|O_APPEND,0644)
if err != nil {
fmt.Println(err)
return
}
temp := []byte("halow")
n, error := file.Write(temp)
//n, error := file.WriteString("hello")
if error != nil {
fmt.Println(err)
return
}
fmt.Println(n)
writer := bufio.NewWriter(file)
n,err := writer.WriteString("fgm")
if error != nil {
fmt.Println(err)
return
}
writer.Flush()
fmt.Println(n)
defer file.Close()
}