java获取文件md5

阅读更多

public static String getFileMd5(File file) {
		FileInputStream in = null;
		try {
			in = new FileInputStream(file);
			byte[] arr = new byte[10240];

			int len = 0;
			MessageDigest messagedigest = java.security.MessageDigest.getInstance("MD5");
			while ((len = in.read(arr)) > 0) {
				messagedigest.update(arr, 0, len);
			}
			return byte2hex(messagedigest.digest());
		} catch (Exception e) {
			log.error(e.getMessage(), e);
		} finally {
			IOUtil.closeQuietly(in);
		}
		return "";
	}


用FileChannel的map会引起文件没释放!

你可能感兴趣的:(java获取文件md5)