-2
我正在嘗試編寫一個程序來解壓縮和重新壓縮文件,而不用寫入Java中的磁盤。到目前爲止,我有,解壓縮並重新壓縮文件而不寫入磁盤 - Java
public void unzipFile(String filePath) {
FileInputStream fis = null;
ZipInputStream zipIs = null;
ZipEntry zEntry = null;
try {
fis = new FileInputStream(filePath);
zipIs = new ZipInputStream(new BufferedInputStream(fis));
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ZipOutputStream zos = new ZipOutputStream(baos);
while ((zEntry = zipIs.getNextEntry()) != null) {
zos.putNewEntry(zEntry);
zos.write(...);
zos.close();
}
} catch (IOException e){
e.printStackTrace();
}
}
}
我的問題是我不知道如何編寫到ZipOutputStream的ZipEntry。我收到錯誤,「java.util.zip.ZipException:無效的項目大小(預期125673,但得到0字節)」。任何人都可以將我指向正確的方向嗎?
嗯,首先,不叫'close()方法'內循環。 – Andreas
你是怎麼調用這個方法的? –
''好吧,對於初學者來說,不要在循環中調用close()。「 - 嚴重 –