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[]数组里,而不想写入文件什么的。 请问如何实现? 谢谢。
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[]数组里,而不想写入文件什么的。 请问如何实现? 谢谢。
参考代码: 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();