1、使用 tcp 协议 读取 输入流的固定长度的字节数

  public static byte[] getTcpSpecificBytes(BufferedInputStream bis,int length) throws IOException{

    byte[] bytes = new byte[len];

    int readLength = 0;

    int hasReadedLength = 0;

    while((readLength = bis.read(bytes, hasReadedLength, length - hasReadedLength)) > 0 ){

      hasReadedLength += readLength; 

    }

    return bytes;

  }

posted on 2017-11-01 13:59  coder_ornot  阅读(1793)  评论(0编辑  收藏  举报