WANG há 6 anos atrás
pai
commit
867b756d13
1 ficheiros alterados com 26 adições e 0 exclusões
  1. 26 0
      src/main/java/cn/com/qmth/examcloud/commons/util/MD5.java

+ 26 - 0
src/main/java/cn/com/qmth/examcloud/commons/util/MD5.java

@@ -1,6 +1,12 @@
 package cn.com.qmth.examcloud.commons.util;
 
+import java.io.File;
+import java.io.FileInputStream;
+
 import org.apache.commons.codec.digest.DigestUtils;
+import org.apache.commons.io.IOUtils;
+
+import cn.com.qmth.examcloud.commons.exception.ExamCloudRuntimeException;
 
 /**
  * 类注释
@@ -30,4 +36,24 @@ public class MD5 {
 	public static String encrypt16(String str) {
 		return DigestUtils.md5Hex(str).substring(8, 24);
 	}
+
+	/**
+	 * 文件md5
+	 *
+	 * @author WANGWEI
+	 * @param file
+	 * @return
+	 */
+	public static String md5Hex(File file) {
+		FileInputStream in = null;
+		try {
+			in = new FileInputStream(file);
+			return DigestUtils.md5Hex(in);
+		} catch (Exception e) {
+			throw new ExamCloudRuntimeException(e);
+		} finally {
+			IOUtils.closeQuietly(in);
+		}
+	}
+
 }