我在学习蓝牙,并且试图编写代码,在连接时保持对输入流的持续监听,然后我遇到了以下这段代码片段:
int data = mmInStream.read();
if(data == 0x0A) {
} else if(data == 0x0D) {
buffer = new byte[arr_byte.size()];
for(int i = 0 ; i < arr_byte.size() ; i++) {
buffer[i] = arr_byte.get(i).byteValue();
}
// Send the obtained bytes to the UI Activity
mHandler.obtainMessage(BluetoothState.MESSAGE_READ
, buffer.length, -1, buffer).sendToTarget();
arr_byte = new ArrayList<Integer>();
} else {
arr_byte.add(data);
}
有人可以解释一下0x0A和0x0D之间的区别吗?并且还可以简要说明一下这段代码。请分享你的看法。
0x0D == '\r'
和0x0A == '\n'
。 - Alexander O'Mara