public static void main(String[] args) throws Exception {
DataOutputStream dos = new DataOutputStream(new FileOutputStream("unzip.qq.html"));
int i = 0;
int len = 1024 * 1024;
byte[] buf = new byte[len];
GZIPInputStream gZIPInputStream = new GZIPInputStream(new FileInputStream("qq.com.html.gzip"));
for (i = 0; i < 1000 && (len = gZIPInputStream.read(buf)) != -1; i++) {
dos.write(buf, 0, len);
}
System.out.println("循环次数:" + i);
}
查看文件,解压缩是成功、完整的。
问题是:
输出的文件unzip.qq.html的大小只有500k字节左右,
却输出
循环次数:188
我的缓冲是int len = 1024 * 1024;啊,1M啊。
------解决方案--------------------
dos.flush();

------解决方案--------------------
要flush的