Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8102811
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T23:20:18+00:00 2026-06-05T23:20:18+00:00

I am trying to download a PDF file with HttpClient. I am able to

  • 0

I am trying to download a PDF file with HttpClient. I am able to get the file but i am not sure how to convert the bytes into a a PDF and store it somewhere on the system

I have the following code, How can I store it as a 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;
        }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T23:20:19+00:00Added an answer on June 5, 2026 at 11:20 pm
    InputStream is = entity.getContent();
    String filePath = "sample.txt";
    FileOutputStream fos = new FileOutputStream(new File(filePath));
    int inByte;
    while((inByte = is.read()) != -1)
         fos.write(inByte);
    is.close();
    fos.close();
    

    EDIT:

    you can also use BufferedOutputStream and BufferedInputStream for faster download:

    BufferedInputStream bis = new BufferedInputStream(entity.getContent());
    String filePath = "sample.txt";
    BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(new File(filePath)));
    int inByte;
    while((inByte = bis.read()) != -1) bos.write(inByte);
    bis.close();
    bos.close();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to convert a multi-page PDF file into a bunch of JPEGs,
I am trying to download a pdf file on my mobile (using Java ME
I'm trying out http requests to download a pdf file from google docs using
i'm trying to using R and RApache to download pdf file with no success.
Trying to download file with apache httpclient library and have a problem with resulting
I'm trying to download a PDF file in Struts Action class. Problem is that
I'm trying to download a file I recieve on the web into my ASP.NET
I am trying to download multiple PDF files as one zip file and then
I'm trying to create a PDF file with a table of data.. But when
I am trying to download some PDF's automatically on a site ( http://bibliotecadigitalhispanica.bne.es )

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.