我一定做错了什么。在 Android 上运行以下代码会生成截断的文件 (_items_),而日志中没有任何异常或问题。使用 OpenJDK 7 运行相同的代码可以正确解压缩文件。
try {
final InputStream fis = new GZIPInputStream(new FileInputStream("/storage/sdcard/_items"));
try {
final FileOutputStream fos = new FileOutputStream("/storage/sdcard/_items_");
try {
final byte[] buffer = new byte[1024];
int n;
while ((n = fis.read(buffer)) != -1) {
fos.write(buffer, 0, n);
}
} finally {
fos.close();
}
} finally {
fis.close();
}
} catch (final IOException e) {
e.printStackTrace();
throw new RuntimeException(e);
}
我已经在 Android 模拟器 (API 18) 和 Desire HD (Android 2.3.5) 上进行了尝试,结果相同。
输入文件(_items):https ://drive.google.com/file/d/0B6M72P2gzYmwaHg4SzRTYnRMOVk/edit?usp=sharing
Android 截断输出文件 (_items_):https ://drive.google.com/file/d/0B6M72P2gzYmwMUZIZ2FEaHNZUFk/edit?usp=sharing