Java class to compute and get a MD5 hash as a string
THe most striking issue I can see in your code is that you're severely limited in the size of files you can compute the hash on. This line of code is particularly jarring:

md.update(Files.readAllBytes(path));


You read the entire file in to memory... which limits you to two things:


the size of your file is limited to the size of your memory ... unless
you have lots of memory, but the file is >2GB at which point you can't create a larger array of bytes.


The reason that the MessageDigest methods contain the update method, is to deal with larger files, and allow you to hash them in parts.

I would use this as an opportunity to learn the somewhat older NIO features: Channels, and Buffers.

Consider the code:

try (MessageDigest md = MessageDigest.getInstance("MD5")) {
    try (FileChannel fc = FileChannel.open(Paths.get(filePath))) {
        long meg = 1024 * 1024;
        long len = fc.size();
        long pos = 0;
        while (pos &lt; len) {
            long size = Math.min(meg, len - pos);
            MappedByteBuffer mbb = fc.map(MapMode.READ_ONLY, pos, size);
            md.update(mbb);
            pos += size;
        }
    } catch (IOException ioe) {
        ....
    }
    byte[] hash = md.digest();
    .....
} catch ( NoSuchAlgorithmException nsae) {
    ....
}


The advantage of the above code is that is plays much closer to the operating system. In theory, it should be the fastest possible way for a Java program to read the file, and it should never transfer the actual file content in to the Java memory space. It removes at least one data copy between the file represented in the OS on disk, and the copy in memory.

There is no limit to the size of file you compute the hash on.