package main import ( "bufio" "fmt" "io" "os" ) func main() { fil, err := os.OpenFile("C:/Documents and Settings/xxx/Desktop/tax.txt", os.O_RDWR|os.O_APPEND, 0420) if err != nil { fmt.Printf("Error: %s\n", err) return } defer fil.Close() fil.WriteString("Hello World!\n") }
===============io WriteString================== package main import ( "fmt" "io" "os" ) func main() { writer, _ := os.OpenFile("C:/Documents and Settings/xxxx/Desktop/Copy of change-sub/b.md", os.O_RDWR|os.O_APPEND, 0420) data := data..xxxxxxx" n, err := io.WriteString(writer, data) if err != nil { fmt.Println("error write", n, "byte") } defer writer.Close() }
有疑问加站长微信联系(非本文作者)