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()
0 0
原创粉丝点击