September 2017
Intermediate to advanced
466 pages
9h 33m
English
The technique in this section will use the ioutil.WriteFile() and ioutil.ReadFile() functions. Note that ioutil.ReadFile() does not implement the io.Reader interface and therefore is a little restrictive.
The Go code for this section is named readAll.go and will be presented in three parts.
The first part has the following Go code:
package main import ( "fmt" "io/ioutil" "os" )
The second part is the following:
func main() {
if len(os.Args) != 3 {
fmt.Println("Please provide two command line arguments!")
os.Exit(1)
}
sourceFile := os.Args[1]
destinationFile := os.Args[2]
The last part is as follows:
input, err := ioutil.ReadFile(sourceFile) if err != nil { fmt.Println(err) os.Exit(1) } err = ioutil.WriteFile(destinationFile, ...Read now
Unlock full access