public static byte[] readBytes(InputStream in) throws IOException {  
    //读取字节的缓冲
    byte[] buffer = new byte[1024];
    //最终的数据
    byte[] result = new byte[0];
    int size = 0;  
    while ((size = in.read(buffer)) != -1) {  
        int oldLen = result.length;
        byte[] tmp = new byte[oldLen + size];
        if (oldLen > 0) {//copy 旧字节
            System.arraycopy(result, 0, tmp, 0, oldLen);
        }
        //copy 新字节
        System.arraycopy(buffer, 0, tmp, oldLen, size);
        
        result = tmp;
    }  
    return result;
} 

 

相关文章:

  • 2022-12-23
  • 2022-02-08
  • 2022-12-23
  • 2021-09-09
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-09-03
  • 2021-08-02
  • 2022-12-23
  • 2021-11-17
  • 2022-12-23
相关资源
相似解决方案