Go语言单个文件拷贝演示代码
package main import "fmt" import "io" import "os" func main(){ w,err := CopyFile("filecopy.go","test.go") if err!=nil{ fmt.Println(err.Error()) } fmt.Println(w) } func CopyFile(src,dst string)(w int64,err error){ srcFile,err := os.Open(src) if err!=nil{ fmt.Println(err.Error()) return } defer srcFile.Close() dstFile,err := os.Create(dst) if err!=nil{ fmt.Println(err.Error()) return } defer dstFile.Close() return io.Copy(dstFile,srcFile) }