字节数组(byte[])转16进制字符串(HexString)

public static String bytesToHexString(byte[] bytes) {
    StringBuffer stringBuffer = new StringBuffer();
    String temp = null;
    for (int i = 0; i < bytes.length; i++) {
        temp = Integer.toHexString(bytes[i] & 0xFF);
        if (temp.length() == 1) {
            stringBuffer.append("0");
        }
        stringBuffer.append(temp);
    }
    return stringBuffer.toString().toUpperCase();
}

参考链接:

关于byte[ ] & 0xFF的问题

继续阅读字节数组(byte[])转16进制字符串(HexString)