public void downloadFile(String url, File targetFile) { CloseableHttpClient httpClient = HttpClients.createDefault(); CloseableHttpResponse response = null; try { HttpGet httpGet = new HttpGet(url); response = httpClient.execute(httpGet); StatusLine statusLine = response.getStatusLine(); if (statusLine.getStatusCode() == 200) { FileOutputStream outputStream = new FileOutputStream(targetFile); InputStream inputStream = response.getEntity().getContent(); byte[] buff = new byte[4096]; boolean var10 = false; int counts; while((counts = inputStream.read(buff)) != -1) { outputStream.write(buff, 0, counts); } outputStream.flush(); outputStream.close(); } } catch (Exception var19) { ; } finally { try { if (response != null) { response.close(); } if (httpClient != null) { httpClient.close(); } } catch (IOException var18) { var18.printStackTrace(); } } }
downloadFile
最新推荐文章于 2024-08-02 00:07:06 发布