In Java, how do I convert a byte array to a string of hex digits while keeping leading zeros? [duplicate]

Check out Hex.encodeHexString from Apache Commons Codec.

import org.apache.commons.codec.binary.Hex;

String hex = Hex.encodeHexString(bytes);

Leave a Comment