Comparing two files
This recipe gives you a hint on how to compare two files. The recipe will show you how to quickly determine whether the files are identical. The recipe will also present you with a way to find differences between the two.
How to do it...
- Open the console and create the folder
chapter06/recipe09
. - Navigate to the directory.
- Create the
comparison.go
file with the following content:
package main import ( "bufio" "crypto/md5" "fmt" "io" "os" ) var data = []struct { name string cont string perm os.FileMode }{ {"test1.file", "Hello\nGolang is great", 0666}, {"test2.file", "Hello\nGolang is great", 0666}, {"test3.file", "Not matching\nGolang is great\nLast line", 0666}, } func main() { files := []*os.File{} for _, fData := range data { f, err := os.Create(fData.name) ...