标签:
package main import ( "fmt" "net/http" "os" ) func DownFile() { userFile := "ttt.exe" fout, err := os.Create(userFile) defer fout.Close() res, err := http.Get("http://10.1.9.102/downpage/up/uu2.4.exe") if err != nil { fmt.Println("downfile error") return } buf := make([]byte, 1024) for { size, _ := res.Body.Read(buf) //读到文件结尾 if size == 0 { break } else { fout.Write(buf[:size]) } } }
标签:
原文地址:http://www.cnblogs.com/ilahsa/p/4411112.html