Mega Code Archive

 
Categories / Java Tutorial / File
 

Calculating the Checksum of a File

import java.io.FileInputStream; import java.util.zip.Adler32; import java.util.zip.CheckedInputStream; public class Main {   public static void main(String[] argv) throws Exception {     CheckedInputStream cis = new CheckedInputStream(new FileInputStream("filename"), new Adler32());     byte[] tempBuf = new byte[128];     while (cis.read(tempBuf) >= 0) {     }     long checksum = cis.getChecksum().getValue();   } }