java两个byte数组合并成一个
byte[] dataPayload = MagicByte.unpackToByte(data);// 对象序列化到字节
String strcon = "00 55 AA FF";//16进制数据
Integer[] integers = parser.StrToToHexByte(strcon);
byte[] Xbyte1 = new byte[]{integers[0].byteValue(), integers[1].byteValue(), integers[2].byteValue(), integers[3].byteValue()};
byte[] bt4 = new byte[Xbyte1.length + dataPayload.length];//两个byte合并成一个
int len = 0;
System.arraycopy(Xbyte1, 0, bt4, 0, Xbyte1.length);
len += Xbyte1.length;
System.arraycopy(dataPayload, 0, bt4, len, dataPayload.length);
System.out.println(bt4);
这篇博客介绍了如何在Java中将两个byte数组合并成一个。首先,通过对象序列化得到`dataPayload`,然后将16进制字符串转换为Integer数组并进一步转化为byte数组`Xbyte1`。最后,通过`System.arraycopy`方法将这两个数组合并到新的byte数组`bt4`中。

266

被折叠的 条评论
为什么被折叠?



