Pages

Java MD5 Of A File

File filex;
        filex = new File(fileURL);
        String md5 = null;
        FileInputStream fileInputStream = null;

        try {
            fileInputStream = new FileInputStream(filex);

            // md5Hex converts an array of bytes into an array of characters representing the hexadecimal values of each byte in order.
            // The returned array will be double the length of the passed array, as it takes two characters to represent any given byte.
            md5 = DigestUtils.md5Hex(IOUtils.toByteArray(fileInputStream));

            fileInputStream.close();
            System.out.print(md5);

        } catch (IOException e) {
            e.printStackTrace();
        }

No comments:

Post a Comment