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) }
当目标文件内容和原文件不符之时 目标文件会被原文件覆盖。
相关文章推荐
- 在Go中复制文件最流行的3种方法
- javaSE之如何将一个文件复制到另一个文件
- Windows 不能复制文件到远程服务器的解决办法
- vim下多文件之间复制
- go语言快速读取配置文件并声明环境变量
- 复制文件(IO)
- 使用输入输出流实现文件复制
- JAVA学习笔记_File类获取、复制当前目录下又有文件
- [问题] [悬赏完成]解密文件 [复制链接]
- linux带缓存IO文件 复制应用
- 安装程序无法复制文件 zclientm.exe
- 文件操作(复制、删除、修改)
- idea的src目录下资源文件无法复制到target下
- IIS6.0安装提示convlog.ex_文件无法复制的解决方法
- 复制文件时,移动硬盘掉电自动重启,复制继续进行,实际上已可能造成复制出错
- linux复制指定文件
- IO(七、)复制文件第二种方式
- 文件的输入输出(举例,文本文件复制) C 语言
- PHP实现文件复制
- MFC下对文件及文件夹的操作(复制、剪切、删除、创建文件夹,写文件)