文件CRC32

import java.util.zip.CRC32;
import java.util.zip.CheckedInputStream;
import java.io.FileInputStream;
import java.io.File;

public class FileToCRCUtil {
   
public static String getFileCRCCode(File file) throws Exception {
       
        FileInputStream fileinputstream = new FileInputStream(file);
        CRC32 crc32 = new CRC32();
        for (CheckedInputStream checkedinputstream =new CheckedInputStream(fileinputstream, crc32);
        checkedinputstream.read() != -1;  ) {
        }
        return Long.toHexString(crc32.getValue());
       

    }


}

你可能感兴趣的:(java)