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

24 lines
302 B
Go
Raw Normal View History

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