This is a created article in which the information may have evolved or changed.
Read all the contents of the file and get the file action object
Package Mainimport ("Bufio" "FMT" "io" "io/ioutil" "OS") func check (e error) {if E! = nil {panic (e)}}func main () {dat, err: = i Outil. ReadFile ("/tmp/dat") Check (err) fmt. Print (string (DAT)) F, err: = OS. Open ("/tmp/dat") Check (ERR) defer f.close ()}
File Write operations
Package Mainimport ("Io/ioutil" "OS") func check (e error) {if E! = nil {panic (e)}}func main () {d1: = []byte ("hello\ngo\n") er r: = Ioutil. WriteFile ("/tmp/dat1", D1, 0644) Check (err) F, err: = OS. Create ("/tmp/dat2") Check (ERR) defer f.close ()}
In fact there is no major operating code, the specific use of a more simple packaging class.
Permission mode of the file Cheetsheet
Note
This series is not a chatty Package API guide, but includes only the most common uses that the authors consider most commonly used. The protests were ineffective.