Is there a way to use ZipOutputStream (from java.util.zip) with a password?
I'm working on copying files from a (unencrypted) zip file into another encrypted zipfile. Using ZipInpuStream/ZipOutputStream it is possible to read from the original zip file into the target zip file but I haven't seen a recipe that talks about how to use password on the ZipOutputStream.
ZipInputStream zis = new ZipInputStream(new FileInputStream(inputFile));
ZipOutputStream zos = new ZipOutputStream(new FileOutputStream(outputFile));
byte[] buff = new byte[1024];
while (true) {
int bytesRead = zis.read(buff, 0, 1024);
if (bytesRead < 0) {
// finished
break;
}
zos.write(buff, 0, bytesRead);
}
zos.flush();
zos.close();
zis.close();