计算文件和字符串的MD5摘要
import com.google.common.hash.HashCode; import com.google.common.hash.Hashing; import com.google.common.io.Files; import org.apache.commons.codec.digest.DigestUtils; import java.io.File; import java.io.IOException; /** * @date 2018/7/18 */ public class MD5Utils { public static String getFileMD5(String filePath) throws IOException { File file = new File(filePath); HashCode hashCode = Files.hash(file, Hashing.md5()); return hashCode.toString(); } public static String genMd5OfString(String str){ return DigestUtils.md5Hex(str); } }
posted on 2018-07-17 23:15 shammgod_code 阅读(169) 评论(0) 编辑 收藏 举报