将字节转换为字符串

Convert bytes to String

我们从蓝牙设备收到以下输出: byte[] bytes = intent.getStringExtra(BluetoothLeService.EXTRA_DATA).getBytes();

输出为: enter image description here

如何在不丢失图片中的 "CE" 个字符的情况下将 bytes[] 转换为 HEX 格式的 String[]?

如果你的字节只是纯文本,那么你可以

new String(bytes, "UTF-8");

如果您的字节创建了一个十六进制字符串,请通过

将该十六进制字符串转换为另一个byte[]
new String(DatatypeConverter.parseHexBinary(new String(bytes)), "UTF-8")