您的位置:首页 > 编程语言 > Go语言

Go 复制文件

2013-07-16 16:02 507 查看
/**
* Created with IntelliJ IDEA.
* User: luosangnanka
* Date: 13-7-16
* Time: 下午3:25
* To change this template use File | Settings | File Templates.
*/
package main

import (
f "fmt"
"io"
"os"
)

func main() {
w, err := CopyFile("sb.log", "hellosb.log")
if err != nil {
f.Println(err.Error())
}
f.Println(w)
}

func CopyFile(src, des string) (w int64, err error) {
srcFile, err := os.Open(src)
if err != nil {
f.Println(err)
}
defer srcFile.Close()

desFile, err := os.Create(des)
if err != nil {
f.Println(err)
}
defer desFile.Close()

return io.Copy(desFile, srcFile)
}


当目标文件内容和原文件不符之时 目标文件会被原文件覆盖。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: