[Go] Go语言单个文件拷贝演示代码 →→→→→进入此内容的聊天室

来自 , 2020-09-14, 写在 Go, 查看 168 次.
URL http://www.code666.cn/view/3c09bb10
  1. package main
  2. import "fmt"
  3. import "io"
  4. import "os"
  5.  
  6. func main(){
  7.         w,err := CopyFile("filecopy.go","test.go")
  8.         if err!=nil{
  9.                 fmt.Println(err.Error())
  10.         }
  11.  
  12.         fmt.Println(w)
  13. }
  14.  
  15. func CopyFile(src,dst string)(w int64,err error){
  16.         srcFile,err := os.Open(src)
  17.         if err!=nil{
  18.                 fmt.Println(err.Error())
  19.                 return
  20.         }
  21.         defer srcFile.Close()
  22.  
  23.         dstFile,err := os.Create(dst)
  24.  
  25.         if err!=nil{
  26.                 fmt.Println(err.Error())
  27.                 return
  28.         }
  29.  
  30.         defer dstFile.Close()
  31.  
  32.         return io.Copy(dstFile,srcFile)
  33.  
  34.  
  35.  
  36. }
  37. //go/5312

回复 "Go语言单个文件拷贝演示代码"

这儿你可以回复上面这条便签

captcha