Skip to content

Instantly share code, notes, and snippets.

@byF
Created October 8, 2020 12:13
Show Gist options
  • Save byF/4a5528e7563ef1316e8d2dfe689d48aa to your computer and use it in GitHub Desktop.
Save byF/4a5528e7563ef1316e8d2dfe689d48aa to your computer and use it in GitHub Desktop.
Calculate md5 file checksum
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