shad-go/lectures/02-interfaces/copyfile2/copy.go
2021-02-25 16:08:25 +03:00

22 lines
299 B
Go

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)
}