本文摘自网络,作者,侵删。
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
}
本文来自:简书
感谢作者:我是不会赢的
查看原文:golang文件复制
相关阅读 >>
jack liu's Golang personal summary notes
更多相关阅读请进入《Go》频道 >>
Go语言101
一个与时俱进的Go编程知识库。