贴出部分代码:private byte[] bf=new byte[8192];
static InputStream inputStream;
static SerialPort serialPort;
static int numBytes; inputStream = serialPort.getInputStream();
//方法一:
numBytes = inputStream.read(readBuffer);//得到numBytes=4096
//方法二:
int ct=inputStream.available();//得到ct=4096
//方法三:
int len = 0;
StringBuffer sbf = new StringBuffer();
String temp = null;
int i = 0;
len = inputStream.read(bf);
while(true){
temp = new String(bf,0,len);
sbf.append(temp);
if(len>=bf.length){
len = inputStream.read(bf);
}else{
break ;
}
}//得到len=4096
//事实证明得到的只有4096个字节位的数据。可是硬件证明发了8192个字节数的数据出来。可是读不到这么多。我设置的也是8192个字节数的byte[].完全无解。希望得到哪位大侠的提点。
如果有必要,我再把所有代码贴出来。
static InputStream inputStream;
static SerialPort serialPort;
static int numBytes; inputStream = serialPort.getInputStream();
//方法一:
numBytes = inputStream.read(readBuffer);//得到numBytes=4096
//方法二:
int ct=inputStream.available();//得到ct=4096
//方法三:
int len = 0;
StringBuffer sbf = new StringBuffer();
String temp = null;
int i = 0;
len = inputStream.read(bf);
while(true){
temp = new String(bf,0,len);
sbf.append(temp);
if(len>=bf.length){
len = inputStream.read(bf);
}else{
break ;
}
}//得到len=4096
//事实证明得到的只有4096个字节位的数据。可是硬件证明发了8192个字节数的数据出来。可是读不到这么多。我设置的也是8192个字节数的byte[].完全无解。希望得到哪位大侠的提点。
如果有必要,我再把所有代码贴出来。
NIO 库中的知识,用ByteBuffer,一般会用到position(),flip(),等一些方法,