Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Write to file

  • Create
  • WriteString
  • write
package main

import (
	"fmt"
	"os"
)

func main() {
	var filename = "z/data.txt"

	text := "Some text"
	var fh, err = os.Create(filename)
	if err != nil {
		fmt.Println(err)
		os.Exit(1)
	}
	fh.WriteString(text + "\n")
	fh.Close()

}