Created
October 8, 2020 12:13
-
-
Save byF/4a5528e7563ef1316e8d2dfe689d48aa to your computer and use it in GitHub Desktop.
Calculate md5 file checksum
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Using.Manager { use => | |
val md = MessageDigest.getInstance("MD5") | |
val fis = use(Files.newInputStream(filePath)) | |
val dos = use(new DigestOutputStream(OutputStream.nullOutputStream(), md)) | |
fis.transferTo(dos) | |
BigInt(1, md.digest()).formatted(s"%0${md.getDigestLength * 2}x") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment