Java tutorial
//package com.java2s; import android.util.Log; import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.util.zip.CRC32; import java.util.zip.CheckedInputStream; public class Main { private static final String TAG = "WXUtil"; private static final char HEX_DIGITS[] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' }; public static String getCRC32(File file) { CRC32 crc32 = new CRC32(); CheckedInputStream checkedinputstream = null; String crc = null; try { checkedinputstream = new CheckedInputStream(new FileInputStream(file), crc32); byte[] buf = new byte[1024]; while (checkedinputstream.read(buf) >= 0) { } crc = Long.toHexString(crc32.getValue()).toUpperCase(); } catch (Exception e) { Log.w(TAG, e); Log.e("WxException", e.getMessage(), e); } finally { if (checkedinputstream != null) { try { checkedinputstream.close(); } catch (IOException e) { } } } return crc; } /** * @hide * @param b * @return */ public static String toHexString(byte[] b) { // String to byte StringBuilder sb = new StringBuilder(b.length * 2); for (int i = 0; i < b.length; i++) { sb.append(HEX_DIGITS[(b[i] & 0xf0) >>> 4]); sb.append(HEX_DIGITS[b[i] & 0x0f]); } return sb.toString(); } }