RT。。 如下代码:
GZIPInputStream gzip = new GZIPInputStream(in);
byte[] buf = new byte[1024]; 
int num = -1;byte[] out;
while((num = gzip.read(buf, 0, buf.length)) != -1)

   out += buf; // 类似这样的效果
}
就是想到数据直接全部保存到byte[]数组里,而不想写入文件什么的。 请问如何实现? 谢谢。

解决方案 »

  1.   

    那就分配一个足够大的数组看看,或者用ByteBuffer
      

  2.   

    谢谢java2000_net兄,gzip数据大小是未知的,请问ByteBuffer如何做? 
      

  3.   

    答:用ByteArrayOutputStream流。
    参考代码: GZIPInputStream gzip = new GZIPInputStream(in);
            byte[] buf = new byte[1024]; 
            int num = -1;
                ByteArrayOutputStream baos=new ByteArrayOutputStream();
            byte[] out=null;
            while((num = gzip.read(buf, 0, buf.length)) != -1)
            { 
              // out += buf; // 类似这样的效果
             baos.write(buf, 0, num);
            }
            baos.flush();
            out=baos.toByteArray();
            baos.close();
      

  4.   

    谢谢jiangnaisong兄,完美解决。