一 示例
private String md5Value(String path) {
InputStream inputStream = null;
String md5 = "";
try {
//url路径
URL url = new URL(path);
//获取连接
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setConnectTimeout(3 * 1000);
//设置请求头
connection.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.110 Safari/537.36");
inputStream = connection.getInputStream();
//DigestUtils为org.apache.commons.codec.digest.DigestUtils下的类
md5 = DigestUtils.md5Hex(inputStream);
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
if (inputStream != null) {
//关闭流
inputStream.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
return md5;
}
在线工具:文件md5在线计算-ME2在线工具 (metools.info)http://www.metools.info/other/o21.html 参考:JAVA中获取文件MD5值的四种方法 - PC君 - 博客园 (cnblogs.com)https://www.cnblogs.com/pcheng/p/7724863.htmlJAVA 实现文件转成MD5码_gyp0307的博客-CSDN博客_java 文件转md5https://blog.csdn.net/gyp0307/article/details/80031541