标签:done ase begin write 效率 pac printf str1 line
视频 http下载代码 dn.go
总体感觉特别简单,网上看了下 net/http ,io这2个库的使用, 几分钟就写完了,感觉cpp 在做工具这块 开发效率的确差太多(没有轮子的话)。
再放一个 go example 网站,https://gobyexample.com/
package main import ( "fmt" "io" "net/http" "os" "strconv" ) /* var ( //url = "http://flv5.bn.netease.com/live163/store/208588/serverpush_18783_1521024752481_208588_0-1.ts" url string = "http://flv5.bn.netease.com/live163/store/208588/serverpush_18783_1521024752481_208588_0-" url_suffix string = ".ts" ) */ func main() { fmt.Println("download begin.....") url := "http://flv5.bn.netease.com/live163/store/208588/serverpush_18783_1521024752481_208588_0-" url_suffix := ".ts" for i := 180; i <= 180; i++ { str_index := strconv.Itoa(i) // 通过Itoa方法转换 //str2 := fmt.Sprintf("%d", i) // 通过Sprintf方法转换 //fmt.Println(str_index) // 打印str1 strFinal := url+str_index+ url_suffix res, err := http.Get(strFinal) if err != nil { panic(err) } f, err := os.Create(str_index+url_suffix) if err != nil { panic(err) } fileSize,writeErr := io.Copy(f, res.Body) fmt.Println(strFinal + " download done,", "file size(byte)=", fileSize) if writeErr != nil { fmt.Println(strFinal + " download failed ", "errorInfo=", writeErr.Error()) panic(err) } } fmt.Println("download finish.") }
标签:done ase begin write 效率 pac printf str1 line
原文地址:https://www.cnblogs.com/scotth/p/9074570.html