Read Write files in Go

Package ioutil implements I/O functions.

import "ioutil"

Read file:

config, error := ioutil.ReadFile("/etc/config")

Write to file:

error := ioutil.WriteFile("/etc/config", config, 0644)

Read direcrtory:

// ioutil.ReadDir returns slice of os.FileInfo
files, error := ioutil.ReadDir("/home/akshay")

if error != nil {
    // Handle error
}

for _, file := range files {
    // file.Size()
    // file.Name()
    // file.IsDir()
}

For more functions, read ioutil doc.

go  note 

See also