80,351
社区成员
发帖
与我相关
我的任务
分享
byte[] tt = new byte[3];//数据头3个字节(前2字节匹配,后一个字节说明后面数据长度)
if (inStream != null) {
for (int i = 0; i < 3; i++) {
try {
tt[i] = (byte) inStream.read();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
String aaa = Hex.encodeHexStr(tt);
String huida = aaa.substring(0, 4);
String dl = aaa.substring(4, 6);
int ddll = Integer.parseInt(dl, 16);//得到数据长度
byte[] tt2 = new byte[ddll];//读取长度的数据
for (int i = 0; i < ddll ; i++) {
try {
tt2[i] = (byte) inStream.read();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}