>>327
public static void main(String[] args) throws UnsupportedEncodingException {
System.out.println(toHexString("0123あいう"));
System.out.println(toHexString("0123あいう", "UTF8"));
}


private static final char[] hex = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
public static String toHexString(String s) {
return toHexString(s.getBytes());
}

public static String toHexString(String s, String charsetName)
throws UnsupportedEncodingException {
return toHexString(s.getBytes(charsetName));
}

public static String toHexString(byte[] b) {
char[] cs = new char[b.length * 2];
for (int i = 0; i < b.length; i++) {
cs[i * 2] = hex[(b[i] >> 4) & 0xF];
cs[i * 2 + 1] = hex[(b[i] >> 0) & 0xF];
}
return new String(cs);
}