惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

T
Tailwind CSS Blog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
雷峰网
雷峰网
量子位
有赞技术团队
有赞技术团队
阮一峰的网络日志
阮一峰的网络日志
The Cloudflare Blog
博客园 - Franky
罗磊的独立博客
宝玉的分享
宝玉的分享
博客园_首页
腾讯CDC
The GitHub Blog
The GitHub Blog
D
DataBreaches.Net
IT之家
IT之家
D
Docker
Microsoft Security Blog
Microsoft Security Blog
博客园 - 司徒正美
V
V2EX
月光博客
月光博客
N
Netflix TechBlog - Medium
爱范儿
爱范儿
I
InfoQ
P
Proofpoint News Feed

博客园 - 但用此心

在CentOS中使用 yum 安装MongoDB及服务器端配置 yum安装mongodb 不错的文章 windows 下,go语言 交叉编译 linux 下 安装go go练习5--生成md5 go练习4--json 序列号反序列化 go练习3 --map的操作 go练习2-go的学习资料 go练习1-翻转字符串 php 定界符 mysql 修改默认配置 提高性能 eclipse 的代码着色插件 --Eclipse Color Theme 将tomcat添加为linux系统服务 在centos linux上安装jdk7 使用excel 展现数据库内容 java 查看线程死锁 linux 配置 java 环境变量 win7 安装windows 服务 报错 System.Security.SecurityException 解决方法 An exception occurred during the Install phase. System.Security.SecurityException: The so
go http 文件下载
但用此心 · 2015-04-09 · via 博客园 - 但用此心
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])
		}
	}

}
    

posted @ 2015-04-09 19:31  但用此心  阅读(1518)  评论(0)    收藏  举报