The java.util.zip package can be used to create a checksum. : Checksum « File « Java Tutorial






import java.io.BufferedInputStream;
import java.io.FileInputStream;
import java.util.Arrays;
import java.util.zip.CRC32;

public class Main {
  public static void main(String[] args) throws Exception{
    BufferedInputStream is = new BufferedInputStream(new FileInputStream("a.exe"));
    byte[] bytes = new byte[1024];
    int len = 0;

    while ((len = is.read(bytes)) >= 0) {
      new CRC32().update(bytes, 0, len);
    }
    is.close();
    System.out.println(Arrays.toString(bytes));

  }
}








11.69.Checksum
11.69.1.A single checksum calculation for multiple files
11.69.2.Compressing Streams: Parity Checksum
11.69.3.Compressing Streams: File Summer
11.69.4.Calculating the Checksum of a Byte Array (Compute Adler-32 checksum)
11.69.5.Compute CRC-32 checksum
11.69.6.Calculating the Checksum of a File
11.69.7.The java.util.zip package can be used to create a checksum.
11.69.8.Check sum for an InputStream