HttpClient下载文件
来源:互联网 发布:linux 重启后存储丢失 编辑:程序博客网 时间:2024/05/15 08:08
private boolean download(String url, String bundleId, String filemd5) {
HttpClient httpClient1 = new DefaultHttpClient();
HttpGet httpGet1 = new HttpGet(url);
try {
HttpResponse httpResponse1 = httpClient1.execute(httpGet1);
StatusLine statusLine = httpResponse1.getStatusLine();
if (statusLine.getStatusCode() == 200) {
String filePath = this.getFilePath(bundleId) + filemd5
+ this.getFileSuffix(url); // 文件路径
File file = new File(filePath);
FileOutputStream outputStream = new FileOutputStream(file);
InputStream inputStream = httpResponse1.getEntity()
.getContent();
byte b[] = new byte[1024];
int j = 0;
while ((j = inputStream.read(b)) != -1) {
outputStream.write(b, 0, j);
}
outputStream.flush();
outputStream.close();
}
} catch (ClientProtocolException e) {
e.printStackTrace();
return false;
} catch (IOException e) {
e.printStackTrace();
return false;
} finally {
httpClient1.getConnectionManager().shutdown();
}
return true;
}
JAVA获取cpu个数: Runtime.getRuntime().availableProcessors()
HttpClient httpClient1 = new DefaultHttpClient();
HttpGet httpGet1 = new HttpGet(url);
try {
HttpResponse httpResponse1 = httpClient1.execute(httpGet1);
StatusLine statusLine = httpResponse1.getStatusLine();
if (statusLine.getStatusCode() == 200) {
String filePath = this.getFilePath(bundleId) + filemd5
+ this.getFileSuffix(url); // 文件路径
File file = new File(filePath);
FileOutputStream outputStream = new FileOutputStream(file);
InputStream inputStream = httpResponse1.getEntity()
.getContent();
byte b[] = new byte[1024];
int j = 0;
while ((j = inputStream.read(b)) != -1) {
outputStream.write(b, 0, j);
}
outputStream.flush();
outputStream.close();
}
} catch (ClientProtocolException e) {
e.printStackTrace();
return false;
} catch (IOException e) {
e.printStackTrace();
return false;
} finally {
httpClient1.getConnectionManager().shutdown();
}
return true;
}
JAVA获取cpu个数: Runtime.getRuntime().availableProcessors()
0 0
- HttpClient 4 文件下载
- httpclient下载文件
- 使用httpclient下载文件
- 通过 HttpClient 下载 文件
- HttpClient下载文件
- 通过 HttpClient 下载 文件
- Httpclient 实现文件下载
- 通过 HttpClient 下载 文件
- httpclient 上传、下载文件
- 通过 HttpClient 下载 文件
- httpclient 文件下载
- HttpClient下载文件
- httpclient 上传文件、下载文件
- 利用HttpClient 4.1 下载文件
- HttpClient 4 实现文件下载
- 转载 httpclient 上传、下载文件
- HttpClient上传图片,下载文件
- 转载 httpclient 上传、下载文件
- Ant企业使用(二)------ant命令及使用
- linux 查看 网络监听的 命令
- boost线程局部存储
- Cunit单元测试
- 备份一个表到新表或备份一个表到架构相同的表
- HttpClient下载文件
- 正则表达式 匹配规则(五)
- ibatis出现Mapped Statements collection already contains value for 错误
- 51nod 1072 博弈 威佐夫游戏
- php中判断shell_exec执行结果
- 剑指offer之面试题27:二叉搜索树与双向链表
- UIAlertContronller的使用
- Node.js 学习笔记 —— 概述
- ssh整合——Hibernate出错 HQL语句出错