现在的情况是这样的,从控制器搞来的InputStream我要读取里面的字节,假设142个字节为一条指令,我知道一共有32条指令就是4544个字节,但是通过
  public void writeStoreData() throws IOException {
  int a = 0;//指令数
  while (inputStream.available()>0){
  storeData = new byte[inputStream.available()];
  for (int i=0;i<inputStream.available();i++){
  inputStream.read(storeData,i,142);
  //满足条件指令就累加
  if (storeData[i]==104||storeData[i+1]==103||storeData[i+2]==43||){
  a++;
  }
  }
  System.out.println(a);
  }
  }
按照理论讲inputstream.available()应该为4544但是我断点看了下实际只有4094,少了部分数据,结果指令只有29条了。。这要怎么办

解决方案 »

  1.   

    只能表示,从你代码的逻辑来看,似乎你对操作流并不熟悉,你这个操作方式丢掉数据是正常的。
    建议Google下流读取的样例代码吧。
      

  2.   

    之前搞界面的,刚接触哈问题是inputStream数据流里面的数据怎么会丢失啊?麻烦帮看看
      

  3.   

    Note that while some implementations of InputStream will return the total number of bytes in the stream, many will not. It is never correct to use the return value of this method to allocate a buffer intended to hold all data in this stream. 很多InputStream的实现是不会返回流中总字节数的,因此用available方法不足取
    直接读,比如read,到流末自然会有指示的