是否可以使用HttpClient下载PDF等文件?

我在这里找到了一些关于如何下载文件的例子,但其中大多数似乎都在使用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. } 

您可以使用HttpURLConnection做的任何事情,通常更好,使用HttpClient查看有关文件传输的示例,您将看到如何做。