C#スクリプトによって提供されるCRC32コードを使用してJavaのファイルを比較する必要があります。java.util.zip.CRC32を使用してCRC32を計算すると、結果は完全に異なります...
私の推測では、C#スクリプトの多項式= 0x2033は、zip.CRC32で使用されているものと同じではありません。多項式を設定することは可能ですか?または、独自の多項式を定義できるCRC32を計算するためのJavaクラスのアイデアはありますか?
更新:問題は多項式ではありません。これはC#とJavaの間で同じです
これは私のコードです、多分私がファイルを読む方法に何か問題がありますか?
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;
}
}
}
どうもありがとう、フランク