You can try java.security.DigestInputStream it's an input stream decorator so that you can calculate the digest while using the input stream as you usually would, instead of having to get an additional pass over the data.
Here's the Syntax:
MessageDigest md = MessageDigest.getInstance("MD5");
try (InputStream is = Files.newInputStream(Paths.get("file.txt"));
DigestInputStream dis = new DigestInputStream(is, md))
byte digest = md.digest();