Skip to content

Instantly share code, notes, and snippets.

@apexdodge
Created April 8, 2020 16:42
Show Gist options
  • Save apexdodge/db1d691d3c1951c114bc75fe0db0aae4 to your computer and use it in GitHub Desktop.
Save apexdodge/db1d691d3c1951c114bc75fe0db0aae4 to your computer and use it in GitHub Desktop.
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.HttpClients;
public void downloadFileUtil(String pdfUrlToDownload) {
HttpClient httpClient = HttpClients.createDefault();
HttpGet httpGet = new HttpGet(pdfUrlToDownload);
HttpResponse response;
response = httpClient.execute(httpGet);
HttpEntity entity = response.getEntity();
FileOutputStream outstream = new FileOutputStream("/storage/directory/filename.pdf");
entity.writeTo(outstream);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment