public void test() { byte[] content = { 0x00, 0x01, 0x12, 0x34, 0x0E, 0x10, 0x02, 0x00, 0x00, 0x00, 0x01, 0x01, 0x12, 0x34, 0x0E, 0x10, 0x01, 0x00, 0x00, 0x02, 0x02, 0x02, 0x12, 0x34, 0x0E, 0x10, 0x01, 0x00, 0x00, 0x03 }; for (int i = 0; i < 3; i++) {
byte[] data = new byte[10];
for (int j = 0; j < 10; j++) { data[j] = content[i * data.length + j];
} System.out.println(ByteUtilities.asHex(data)); }
}
public void test() { byte[] content = { 0x00, 0x01, 0x12, 0x34, 0x0E, 0x10, 0x02, 0x00, 0x00, 0x00, 0x01, 0x01, 0x12, 0x34, 0x0E, 0x10, 0x01, 0x00, 0x00, 0x02, 0x02, 0x02, 0x12, 0x34, 0x0E, 0x10, 0x01, 0x00, 0x00, 0x03 }; byte[] data = new byte[10]; int temp = 0; for (int i = 0; i < 3; i++) { for (int j = 0; j < 10; j++) { if (temp < 10 && temp != 10) { data[j] = content[j]; } else { data[j] = content[temp]; } temp = temp + 1; } System.out.println(ByteUtilities.asHex(data)); } }
两种方法,自己试试吧
先把byte数组输出,再分到各个数组里就行了,