package main
import (
"bufio"
"fmt"
"io"
"net/http"
"os"
)
func main() {
DownFile()
}
func DownFile() {
url := "https://s3.pstatp.com/toutiao/xitu_juejin_web/img/juejin-extension-icon.4b79fb4.png"
resp,err:=http.Get(url)
if err !=nil{
fmt.Fprintf(os.Stderr,"get url failed",err)
return
}
defer resp.Body.Close()
out,err:=os.Create("/tmp/dalu.png")
wt:=bufio.NewWriter(out)
defer out.Close()
n,err:=io.Copy(wt,resp.Body)
fmt.Println("write",n)
if err!=nil{
panic(err)
}
wt.Flush()
}
有疑问加站长微信联系(非本文作者)