I always get an exception
Exception in thread "main" java.util.FormatFlagsConversionMismatchException: Conversion = h, Flags = 0
on this line of code
String.format("%02H", data[i]);
the data array holds char variables.
I want to print these characters in hex format like 09, not only 9.
I think you need to use
String.format("%02X", (int)data[i]);instead.Take a look at the answers to Java code To convert byte to Hexadecimal for an expanded discussion on the topic.