int count = 0;
while (count == 0) {
count = mmInStream.available();//输入流中的数据个数。
}
System.out.println("字符串总长度为:"+count);
int readCount = 0; // 已经成功读取的字节的个数
while (readCount < count) {
readCount += mmInStream.read(buffer, readCount, count - readCount);
}
就是这段代码,如果发送端发送10个字符,我这里有时会先接收一个字符,然后又接收9个。不是整体一下子接收过来。我把上述代码放到了一个线程的while循环中。
while (count == 0) {
count = mmInStream.available();//输入流中的数据个数。
}
System.out.println("字符串总长度为:"+count);
int readCount = 0; // 已经成功读取的字节的个数
while (readCount < count) {
readCount += mmInStream.read(buffer, readCount, count - readCount);
}
就是这段代码,如果发送端发送10个字符,我这里有时会先接收一个字符,然后又接收9个。不是整体一下子接收过来。我把上述代码放到了一个线程的while循环中。
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货