我在这里找到了一些有关如何下载文件的示例,但其中大多数似乎都在使用HttpURLConnection。HttpClient可以下载文件吗?
使用httpclient非常简单。这是本教程的链接。
http://hc.apache.org/httpcomponents-client- ga/tutorial/html/fundamentals.html#d5e43
HttpClient httpclient = new DefaultHttpClient(); HttpGet httpget = new HttpGet(urltofetch); HttpResponse response = httpclient.execute(httpget); HttpEntity entity = response.getEntity(); if (entity != null) { long len = entity.getContentLength(); InputStream inputStream = entity.getContent(); // write the file to whether you want it. }