HttpClient下载文件
2012-12-25 17:06
369 查看
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 文件下载
- HttpClient使用之下载远程服务器中的文件(注意目录遍历漏洞)
- java利用org.apache.http.client下载文件
- HttpClient文件上传下载
- android 使用AsyncHttpClient框架上传文件以及使用HttpURLConnection下载文件
- org.apache.http.client.HttpClient 访问服务器限速下载文件
- httpclient proxy 获取权限,然后下载文件
- [转]httpclient 上传文件、下载文件
- CAtlHttpClient 下载文件保存到本地,拿去就能用简单易懂
- HttpClient使用之下载远程服务器中的文件(注意目录遍历漏洞)
- 关于 tornado.simple_httpclient SimpleAsyncHTTPClient fetch下载大文件,默认60s的问题
- HttpClient使用post方式模拟表单提交数据到服务器并下载服务器文件
- java应用集锦9:httpclient4.2.2的几个常用方法,登录之后访问页面问题,下载文件
- android 使用AsyncHttpClient框架上传文件以及使用HttpURLConnection下载文件
- HttpClient使用post方式模拟表单提交数据到服务器并下载服务器文件
- HttpClient 使用get方式发送数据到服务器并下载服务器文件
- HttpClient上传图片,下载文件
- httpclient4.2.2的几个常用方法,登录之后访问页面问题,下载文件
- httpclient4.2.2的几个常用方法,登录之后访问页面问题,下载文件
- HttpClient 4 文件下载