package main import ( "os" "fmt" "io/ioutil" "io" "bytes" ) func main() { /****文件复制*****/ file, err := os.Open("1.zip") if err != nil { fmt.Println(err) return } bt, err := ioutil.ReadAll(file) if err != nil { fmt.Println(err) return } CopyFile(bt, "2.zip") /****Http下载方式*****/ //url:="下载地址" //resp, err := http.Get(url) //if err != nil { // return err //} //println(resp.Header.Get("content-type")) //defer resp.Body.Close() //b, err := ioutil.ReadAll(resp.Body) //CopyFile(b, "2.zip") } func CopyFile(byte []byte, dst string) (w int64, err error) { dstFile, err := os.Create(dst) if err != nil { fmt.Println(err.Error()) return } defer dstFile.Close() return io.Copy(dstFile, bytes.NewReader(byte)) }