shad-go/lectures/02-interfaces/copyfile2/copy.go

23 lines
299 B
Go
Raw Permalink Normal View History

package copyfile2
import (
"io"
"os"
)
func CopyFile(dstName, srcName string) (written int64, err error) {
src, err := os.Open(srcName)
if err != nil {
return
}
defer src.Close()
dst, err := os.Create(dstName)
if err != nil {
return
}
defer dst.Close()
return io.Copy(dst, src)
}