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

  • Home
  • SEARCH
  • 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 5969151
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T20:11:24+00:00 2026-05-22T20:11:24+00:00

Trying to download file with apache httpclient library and have a problem with resulting

  • 0

Trying to download file with apache httpclient library and have a problem with resulting file being smaller than the original (approximately 32-32kb, when normal file size is 92-93) and cannot be opened normally in pdf viewer.
Can someone explain me why this can be happening ? (Using firefox to download this file can sometimes lead to file being downloaded fully and sometimes being downloaded partly)

Here is code I was using to download file via URL

    URL url = new URL("pathtofile");
    final URLConnection connection = url.openConnection();

    final InputStream is = connection.getInputStream();
    FileOutputStream fos = new FileOutputStream("C://result1.pdf");

    byte buffer[] = new byte[1024];
    int bytesRead; 
    while ((bytesRead = is.read(buffer)) >= 0) {        
        fos.write(buffer, 0, bytesRead);
    }
    fos.flush();
    fos.close();
    is.close();

P.S. Was trying to download this file using HttpClient apache library, same result.

UPDATED: Monitoring traffic with network tool I found the difference between receiving file via Firefox and application.

With Firefox first HttpPayloadLine was :

HTTPPayloadLine: 83 Td
/F2 5.80476 Tf
(A:\040Asinis\04017.12.10\04008:32\040laboratorij) Tj
100 Tz
1 1 1 rg
/F1 5.80476 Tf
0 0 0 rg
104.4856 0 Td
<0145> Tj
1 1 1 rg
0 0 0 rg
3.62799 0.72565 Td
/F2 5.80476 Tf
(\040) Tj
1 1 1 rg
0.83137 0.81569 0.78431 RG
ET
51

With application first HttpPayload was

HTTPPayloadLine: CWgC,ú&ÿ3@Î"ݯV¨®~×>×)\ªleÚlµï½ci
¤Ãðð’È/CÈAø¯ª ÍübA«1Ãÿ Åç«VɬZòYóóy7»ÇH.o²e<qZna3l±°¥þ6ñþ[2YÚ1ì³Eë-ÓÊÏ$y:tÎà![ËÅS¤¿É¡¢è,þ|ºs¨)@¢Qâ¯ÝF~}oµÒ>¦ OAxz³äÒ.ß9
æÃZ¤ùÒ¨*«øUή+4×

This measurements was taken via Microsoft Network Monitor

LAST UPDATE It was a server problem after all, after they fixed that files are downloaded successful

  • 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-05-22T20:11:24+00:00Added an answer on May 22, 2026 at 8:11 pm

    Try changing to

    while ((bytesRead = in.read(buffer)) != -1) {
     byte[] tmp = ArrayUtils.subarray(buffer, 0, bytesRead);
     fos.write(tmp);
    }
    

    you mite get 0 bytes back but that does not mean its finished.Also write only bytes that you received not buffer.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to use SQL Server 2000 DTS Package to download a file from
I'm trying to use the WebClient class to download a html file from another
Trying to force-download file with PHP using usual: header(Content-type: $type ); header(Content-Disposition: attachment; filename=$name);
I am trying to download a file from the net and write it to
i'm trying to download .zip file from bluehost server to my computer. Like this
I am getting a AWS::S3::NoConnectionEstablished exception when trying to download a file using paperclip
I'm getting a FileNotFoundException when I'm trying to download the file http://tfob.azstarnet.com/images/authors/Alcal%C3%A1_Kathleen_small.jpg . The
server: apache http server 2.2 problem: code does not load my text file hello
I am trying download zip file to SD card. I download it correctly, but
I'm trying to download file with Python using IE: from win32com.client import DispatchWithEvents class

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.