这里以下载迅雷U享版为例。

示例代码:

package com.zifeiy.snowflake.handle.filesget;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection; public class HttpFileGetter { public boolean download(String urlString, File localFile) {
try {
URL url = new URL(urlString);
URLConnection connection = url.openConnection();
connection.setConnectTimeout(5*1000);
InputStream inputStream = connection.getInputStream();
byte[] byteArr = new byte[1024];
int len;
File dir = localFile.getParentFile();
if (dir.exists() == false)
dir.mkdirs();
OutputStream outputStream = new FileOutputStream(localFile);
while ((len = inputStream.read(byteArr)) != -1) {
outputStream.write(byteArr, 0, len);
}
outputStream.close();
inputStream.close();
} catch (IOException e) {
e.printStackTrace();
return false;
} return true;
} // main for test
public static void main(String[] args) {
HttpFileGetter httpFileGetter = new HttpFileGetter();
httpFileGetter.download("http://down.sandai.net/ThunderVIP/ThunderVIP-xlgw.exe", new File("D:\\test_download.exe"));
}
}

下载下来的程序运行也没有问题:

最新文章

  1. 用FineReport做的共建共享填报系统
  2. java 读取数据库中表定义
  3. iOS应用数据存储2-SQLite3数据库
  4. 【crunch bang】 tint2-用来控制桌面的布局
  5. ListBox重绘
  6. "Failed to fetch URL https://dl-ssl.google.com/android/repository/addons_list.xml,reason: Connection
  7. C# 面向对象 , 类与对象
  8. graph driver-device mapper-01driver初始化
  9. API变了,客户端怎么办?
  10. thinkphp5自动完成
  11. PowerCLI: One-Liner to get VMs, Clusters, ESX Hosts and Datastores并导入数据库中
  12. ASP.NET MVC页面报错System.InvalidOperationException The view found at '~/Views/Home/Index.cshtml' was not created.
  13. 洛谷P1582 倒水题解
  14. Web QQ 协议 登录加密算法 —— VC++实现
  15. python基础一 ------可迭代类型的连接
  16. cto职责
  17. PMS-授权中心
  18. 13,EasyNetQ-错误条件
  19. oracle基础 管理索引
  20. 3. sklearn的K-Means的使用

热门文章

  1. Airtest---UI自动化测试项目
  2. Spark RDD 到 LabelPoint的转换(包含构造临时数据的方法)
  3. [Javascript] Construct a Regex to Match Twitter Mentions with Regexr
  4. boost::singleton
  5. MySql存储过程参考
  6. PostgreSQL 多版本的实现与Innodb和oracle的差别
  7. [luogu] zpl的数学题1
  8. 【原创】go语言学习(八)切片
  9. linux 查看内存条详情命令
  10. 牛客训练21674——牛牛与LCM