main Package Penalty for Import ( " the BUFIO " " fmt " " os " ) // to create additional write or record write cover to open a file, / * steps to open a file to determine the results, create a writer, call writer method. Close file * / FUNC main () { // If the file does not exist, create a write-only mode + + append data to generate the file permissions are 666 File, ERR: = os.OpenFile ( " C: / the Users / Administrator / Desktop / test .txt " , os.O_CREATE | os.O_WRONLY | os.O_APPEND, 0666 ) // If the file does not exist, create and write-only mode and overwrite files // file, ERR: = os.OpenFile (" C: / the Users / Administrator / Desktop / test .txt ", os.O_CREATE | os.O_WRONLY | os.O_TRUNC, 0666) IF ERR =!{nil fmt.Println ( " file open failure, ERR = " , ERR) return } the defer FUNC () { File.close () fmt.Println ( " file closed " ) } () Writer: = bufio.NewWriter (File ) // write data in batches, write string writer.WriteString ( " a \ n- " ) writer.WriteString ( " B \ n- " ) writer.WriteString ( " C \ n- " ) writer.WriteString ( " D \ the n- " ) // write word writer.WriteRune ( ' you ' ) writer.Write ([] byte { 123 }) // flushed to disk writer.Flush () }