我使用下面的代码和LZ4库在java中进行压缩。如果我尝试对相同的文件名再次调用此方法,它会用新内容覆盖,而不是追加。有没有一种方法可以使用LZ4追加?我只想稍后将另一个文件添加到现有的zip存档中。
public void zipFile(File[] fileToZip, String outputFileName, boolean activeZip)
{
try (FileOutputStream fos = new FileOutputStream(new File(outputFileName));
LZ4FrameOutputStream lz4fos = new LZ4FrameOutputStream(fos);)
{
for (File a : fileToZip)
{
try (FileInputStream fis = new FileInputStream(a))
{
byte[] buf = new byte[bufferSizeZip];
int length;
while ((length = fis.read(buf)) > 0)
{
lz4fos.write(buf, 0, length);
}
}
}
}
catch (Exception e)
{
LOG.error("Zipping file failed ", e);
}
}发布于 2020-10-27 03:29:20
我唯一能弄清楚该怎么做的方法就是发送
new FileOutputStream(new File(outputFileName),false)在try-with-resources中
https://stackoverflow.com/questions/64543269
复制相似问题