我試圖下載使用HttpClient的PDF文件。我能夠拿到文件,但我不知道如何將字節轉換成PDF格式,並在一些地方保存它的系統如何與HttpClient的下載的文件保存到特定的文件夾
我有下面的代碼,我怎麼可以把它存儲爲PDF?
public ???? getFile(String url) throws ClientProtocolException, IOException{
HttpGet httpget = new HttpGet(url);
HttpResponse response = httpClient.execute(httpget);
HttpEntity entity = response.getEntity();
if (entity != null) {
long len = entity.getContentLength();
InputStream inputStream = entity.getContent();
// How do I write it?
}
return null;
}
HttpClient在內部優化了讀取操作。沒有必要用另一種緩衝層 – oleg
我不能直接寫入該文件的路徑,我不得不使用'檔案文件=新的文件(context.getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS),「filename.jpg」);'爲寫入外部存儲器,以便其他應用程序可以看到我的應用程序 – Aaron