How can I zip more than one file? I'm only getting one. This is my code:
public static void compactarParaZip(String arqSaida, String arqEntrada)
throws IOException {
int cont;
byte[] dados = new byte[TAMANHO_BUFFER];
BufferedInputStream origem = null;
FileInputStream streamDeEntrada = null;
FileOutputStream destino = null;
ZipOutputStream saida = null;
ZipEntry entry = null;
try {
destino = new FileOutputStream(new File(arqSaida));
saida = new ZipOutputStream(new BufferedOutputStream(destino));
File file = new File(arqEntrada);
streamDeEntrada = new FileInputStream(file);
origem = new BufferedInputStream(streamDeEntrada, TAMANHO_BUFFER);
entry = new ZipEntry(file.getName());
saida.putNextEntry(entry);
while ((cont = origem.read(dados, 0, TAMANHO_BUFFER)) != -1) {
saida.write(dados, 0, cont);
}
origem.close();
saida.close();
} catch (IOException e) {
throw new IOException(e.getMessage());
}
}
}
If I pass 2 more files as a parameter in compactarParaZip
method, what should I change? I can do Array
of type File
, so I think I could pass several files.