我们有以下使用GZIPOutputStream压缩文件的Java方法
private void archive(Path originalFile) {
Path tempFile = originalFile.resolveSibling(originalFile.toFile().getName() + TEMPORARY_FILE_EXTENSION);
Path gzippedFile = originalFile.resolveSibling(originalFile.toFile().getName() + ARCHIVED_FILE_EXTENSION);
try {
try (FileInputStream input = new FileInputStream(originalFile.toFile());
BufferedOutputStream output = new BufferedOutputStream(new GZIPOutputStream(new FileOutputStream(tempFile.toFile())))) {
IOUtils.copy(input,output);
output.flush();
}
Files.move(tempFile, gzippedFile, StandardCopyOption.REPLACE_EXISTING);
Files.delete(originalFile);
LOGGER.info("Archived file {} to {}", originalFile, gzippedFile);
} catch (IOException e) {
LOGGER.error("Could not archive file {}: " + e.getMessage(), originalFile, e);
}
try {
Files.deleteIfExists(tempFile);
} catch (IOException e) {
LOGGER.error("Could not delete temporary file {}: " + e.getMessage(), tempFile, e);
}
}问题是,如果我们手动解压缩文件:
gzip -d file_name结果解压缩的文件与原始文件不匹配。,文件大小和总行数减少了。例如,从33 to到32 to,损失800 K行。
这个问题是否与我们正在压缩的文件的编码(EBCDIC)有关?https://en.wikipedia.org/wiki/EBCDIC
发布于 2019-03-13 07:17:00
经过几次测试,我们无法重现这个问题,这肯定与在压缩过程中没有足够的空间有关。@SirFartALot谢谢你指出这一点。
https://stackoverflow.com/questions/55123459
复制相似问题