1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
| import java.security.MessageDigest; import static org.apache.commons.codec.digest.MessageDigestAlgorithms.MD5; public class TestFileClient { @Test public void test(){ InputStream is = new FileInputStream(new File("/data/source.txt")); MessageDigest messageDigest = MessageDigest.getInstance(MD5); byte[] buffer = new byte[1024]; int len = 0; while ((len = is.read(buffer)) != -1) { messageDigest.update(buffer, 0, len); } String md5 = (new String(Hex.encodeHex(messageDigest.digest()))); } }
|
本文地址: https://github.com/maxzhao-it/blog/post/7e26006c/