java获取文件的md5值
2016-06-24 17:44
381 查看
import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; import java.math.BigInteger; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; public class Test { public static void main(String[] args) { try { File file = new File("F://test.txt"); FileInputStream fis = new FileInputStream(file); MessageDigest md = MessageDigest.getInstance("MD5"); byte[] buffer = new byte[1024]; int length = -1; while ((length = fis.read(buffer, 0, 1024)) != -1) { md.update(buffer, 0, length); } BigInteger bigInt = new BigInteger(1, md.digest()); System.out.println("文件md5值:" + bigInt.toString(16)); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } }
相关文章推荐
- web容器启动Spring
- Java中有关File类listFiles的一个小测试
- SpringMVC+Spring+hibernate整合及分页
- Eclipse快捷方式
- Java获取路径
- RxJava 学习笔记(三)
- JAVA Servlet API简介及接口与类的用法
- OC中的@interface和java中的区别以及 @implementation @protocol
- eclipse无法启动的各种解决方法
- 华为机试---聊天
- java代码在内存后续(static)
- [疯狂Java]面向对象:初始化块、初始化代码、初始化顺序
- 解决ubuntu eclipse中 Android SDK Manager 图标不见的方法
- maven项目src/main/java包compilation error
- java 第3章 运算符
- spring boot项目引用kaptcha
- java基础—方法重载(overload)
- java中堆和堆栈的区别
- Eclipse 使用方式窍门
- JSON详细学习之Gson in JAVA