|
@@ -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);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
}
|