Android File Checksum getChecksum(String filePath)

Here you can find the source of getChecksum(String filePath)

Description

get Checksum

Declaration

public static String getChecksum(String filePath)
            throws FileNotFoundException, IOException 

Method Source Code

//package com.java2s;
import java.io.BufferedInputStream;

import java.io.FileInputStream;
import java.io.FileNotFoundException;

import java.io.IOException;

import java.util.zip.CRC32;
import java.util.zip.CheckedInputStream;

public class Main {
    public static String getChecksum(String filePath)
            throws FileNotFoundException, IOException {
        FileInputStream file = new FileInputStream(filePath);
        CheckedInputStream check = new CheckedInputStream(file, new CRC32());
        BufferedInputStream in = new BufferedInputStream(check);
        String checkSum = "";

        while (in.read() != -1) {
            // Read file in completely
        }/*from   w w  w.ja v  a2 s  . co  m*/

        if (in != null) {
            in.close();
        }

        if (file != null)
            file.close();

        if (check != null) {
            checkSum = String.valueOf(check.getChecksum().getValue());
            check.close();
        }

        return checkSum;
    }
}

Related

  1. checksumFile(final Checksum chk, final String fname)
  2. computeChecksum(String path)
  3. verifyChecksum(String path)
  4. checkSum(File f)