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 111603
In Process

The Archive Base Latest Questions

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

I have a problem, which I do not seem to be able to solve…

  • 0

I have a problem, which I do not seem to be able to solve… I do a http download of a file, but the CRC32 of the file on the server and on the client do not match. Also, the file has different size, so obviously I must be doing something wrong… when I download via Firefox, the filesize is ok… so I guess it is somewhere in the client code.

I already found Corrupt file when using Java to download file, but that didn’t help me either…

Here’s the code:

private void downloadJar(String fileName, long crc32Server) throws IOException {   System.out.println('Downloading file '' + fileName + '' from server '' + mServer + ''.');   HttpURLConnection sourceConnection = null;   BufferedInputStream inputStream = null;   BufferedWriter fileWriter = null;   long crc32Client;   try {     URL sourceURL = new URL(fileName);     try {       sourceConnection = (HttpURLConnection)sourceURL.openConnection();     }     catch (MalformedURLException exc) {       throw new RuntimeException('Configured URL caused a MalformedURLException: ', exc);     }     sourceConnection.setRequestProperty('Accept-Encoding', 'zip, jar');     sourceConnection.connect();     inputStream = new BufferedInputStream(sourceConnection.getInputStream());     fileWriter = new BufferedWriter(new FileWriter(targetFolder + File.separator + fileName));     CRC32 crc32 = new CRC32();     for (int singleByte = inputStream.read(); singleByte != -1; singleByte = inputStream.read()) {       fileWriter.write(singleByte);       crc32.update(singleByte);     }     crc32Client = crc32.getValue();   }   finally {     if (inputStream != null) {       inputStream.close();     }     if (fileWriter != null) {       fileWriter.flush();       fileWriter.close();     }     if (sourceConnection != null) {       sourceConnection.disconnect();     }   }   if (crc32Client != crc32Server) {     //      deleteFile(fileName);     throw new IOException('CRC32 did not match for file '' + fileName + '': ' + crc32Client + '!='         + crc32Server);   } } 
  • 1 1 Answer
  • 1 View
  • 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. 2026-05-11T02:24:44+00:00Added an answer on May 11, 2026 at 2:24 am

    You should use a BufferedOutputStream instead of a FileWriter/BufferedWriter. In general, *Streams handle raw binary data, while *Writers handle character data (which is an interpretation of the raw binary data for a given character encoding).

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

Sidebar

Related Questions

I have some files in a directory tree which is being served over HTTP.
I have a script which is running as root, it's supposed to store it's
I have a page with a wrapper div which contains a background image and
Before I get flamed and down-voted without mercy, my company will not allow the
I am about to develop a program which will be installed and run as
Have/Want List Matching Algorithm I am implementing an item trading system on a high-traffic
Is it possible to embed a console window inside a WPF window? As a
This is my first post, so please be gentle. I've been playing around with
We are trying to use Test Complete 7 to test an application compiled in

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.