要完成@captncraig答案,如果您想知道这两个文件是否相同,可以使用OS软件包中的SameFile(fi1, fi2 FileInfo)方法。

SameFile reports whether fi1 and fi2 describe the same file. For example, on Unix this means that the device and inode fields of the two underlying structures are identical;
否则,如果要检查文件内容,这里有一个解决方案,它逐行检查两个文件,避免加载内存中的整个文件。 首先尝试:https://play.golang.org/p/NlQZRrW1dT 编辑:按字节块读取,如果文件大小不同,则快速失败。 https://play.golang.org/p/YyYWuCRJXV
const chunkSize = 64000
func deepCompare(file1, file2 string) bool {
    // Check file size ...
f1, err := os.Open(file1)
    if err != nil {
        log.Fatal(err)
    }
f2, err := os.Open(file2)
    if err != nil {
        log.Fatal(err)
    }
for {
        b1 := make([]byte, chunkSize)
        _, err1 := f1.Read(b1)
b2 := make([]byte, chunkSize)
        _, err2 := f2.Read(b2)
if err1 != nil || err2 != nil {
            if err1 == io.EOF && err2 == io.EOF {
                return true
            } else if err1 == io.EOF || err2 == io.EOF {
                return false
            } else {
                log.Fatal(err1, err2)
            }
        }
if !bytes.Equal(b1, b2) {
            return false
        }
    }
}