gpt4 book ai didi

java - 将大型 CSV 流写入内存中的 ZipOutputStream 消耗的内存是否与 CSV 或潜在 zip 的大小一样多?

转载 作者:行者123 更新时间:2023-12-02 11:35:46 28 4
gpt4 key购买 nike

我的 Zip 包含一个大的 CSV。 (因此它是 zipper 的)我想向 CSV 添加一列并再次对其进行压缩。

我可以接受将整个 Zip 存储在内存中,但绝对不能接受整个 CSV。因此,如果我将 CSV block 逐 block 写入 ZipOutputStream 的特定 ZipEntry(内存中)。它会像 CSV 数据那样占用堆中的整个空间吗?还是会占用 Zip 文件所需的空间?

最佳答案

这就是我们通常从 zip 复制到 zip 的方式:

        byte[] buffer = new byte[8192];
while ((currentEntry = zipInputStream.getNextEntry()) != null) {
ZipEntry newEntry = new ZipEntry(currentEntry.getName());
zipOutputStream.putNextEntry(newEntry);
int length;
while ((length = zipInputStream.read(buffer)) > 0) {
zipOutputStream.write(buffer, 0, length);
}
zipOutputStream.closeEntry();
}

从这段代码中我们可以假设程序将以 8k 为单位进行读/写

关于java - 将大型 CSV 流写入内存中的 ZipOutputStream 消耗的内存是否与 CSV 或潜在 zip 的大小一样多?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48960309/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com