首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >意外的Java GZIPOutputStream结果

意外的Java GZIPOutputStream结果
EN

Stack Overflow用户
提问于 2019-03-12 14:07:07
回答 1查看 166关注 0票数 0

我们有以下使用GZIPOutputStream压缩文件的Java方法

代码语言:javascript
复制
 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);
    }
}

问题是,如果我们手动解压缩文件:

代码语言:javascript
复制
gzip -d file_name

结果解压缩的文件与原始文件不匹配。,文件大小和总行数减少了。例如,从33 to到32 to,损失800 K行。

这个问题是否与我们正在压缩的文件的编码(EBCDIC)有关?https://en.wikipedia.org/wiki/EBCDIC

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-03-13 07:17:00

经过几次测试,我们无法重现这个问题,这肯定与在压缩过程中没有足够的空间有关。@SirFartALot谢谢你指出这一点。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/55123459

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档