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
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.