golang 文件复制
/**
**/
func Copy(srcFile, dstFile string) (int64, error) {
sourceFileStat, err := os.Stat(srcFile)
if err != nil {
return 0, err
}
if !sourceFileStat.Mode().IsRegular() {
return 0, fmt.Errorf("%s is not a regular file", srcFile)
}
source, err := os.Open(srcFile)
if err != nil {
return 0, err
}
defer source.Close()
destination, err := os.Create(dstFile)
if err != nil {
return 0, err
}
defer destination.Close()
nBytes, err := io.Copy(destination, source)
return nBytes, err
}
有疑问加站长微信联系(非本文作者)