As discussed in Chapter 6, File Input and Output, in this chapter, we will talk about opening a file for writing without destroying its existing data.
The Go program that will illustrate the technique, appendData.go, will accept two command-line arguments: the message you want to append and the name of the file that will store the text. This program will be presented in three parts.
The first part of appendData.go contains the following Go code:
package main import ( "fmt" "os" "path/filepath" )
As expected, the first part of the program contains the Go packages that will be used in the program.
The second part is the following:
func main() { arguments := os.Args if len(arguments) != 3 { fmt.Printf("usage: %s message filename\n", filepath.Base(arguments[0])) os...