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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T10:56:49+00:00 2026-05-18T10:56:49+00:00

I have to compare files with java with a CRC32 code provided by a

  • 0

I have to compare files with java with a CRC32 code provided by a C# script. When I calculate the CRC32 with java.util.zip.CRC32 the result is completely different …

My guess is that the polynom = 0x2033 of the C# script is not the same as used in zip.CRC32. Is it possible to set the polynom ? Or any ideas of a java-class for calculating a CRC32 where you can define your own polynom?

UPDATE: problem is not the polymnom. This is the same between C# and Java

This is my code, maybe something is wrong in the way I read the file?

package com.mine.digits.internal.contentupdater;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.zip.CRC32;

public class CRC 
{
    public static String doConvert32(File file)
    {
        byte[] bytes = readBytesFromFile(file); // readFromFile(file).getBytes();

        CRC32 x = new CRC32();
        x.update(bytes);

        return (Long.toHexString(x.getValue())).toUpperCase();
    }

    /** Read the contents of the given file. */
    private static byte[] readBytesFromFile(File file)
    {
        try
        {
            InputStream is = new FileInputStream(file);

            long length = file.length(); 
            if (length > Integer.MAX_VALUE) { 
                // File is too large 
            } 

            byte[] bytes = new byte[(int)length]; 
            int offset = 0; 
            int numRead = 0; 
            while (offset < bytes.length && (numRead=is.read(bytes, offset, bytes.length-offset)) >= 0)
            { 
                offset += numRead; 
            } 

            // Ensure all the bytes have been read in 
            if (offset < bytes.length) { 
                System.out.println("Could not completely read file " + file.getName()); 
            } 

            // Close the input stream and return bytes 
            is.close(); 

            return bytes;
        }
        catch (IOException e)
        {
            System.out.println("IOException " + file.getName()); 

            return null;
        }
    }
}

Thanks a lot,
Frank

  • 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-18T10:56:50+00:00Added an answer on May 18, 2026 at 10:56 am

    Solved by copying the code from C# and convert it to a Java-class…

    So now both use the same code, only had to do some minor changes for unsigned <> signed bytes differences.

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

Sidebar

Related Questions

I am trying to compare two decimal values in Java script. I have two
Does a comparison sort have to compare the A[i] largest and A[i+1] largest values?
I have 2 strings that I'd like to compare, and return the positions of
I have 2 arrays of 16 elements (chars) that I need to compare and
I have an integer field in a ClientDataSet and I need to compare to
I have two arrays of System.Data.DataRow objects which I want to compare. The rows
I have a HashMap relating Keys to Strings, and I need to compare some
Do you have any experience with T4 and T4 Editor ? Can you compare
I would like to compare two dates in javascript. I have been doing some
Are there any tools to effectively compare two XML schema's? I have seen some

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.