esse código compacta varios arquivos da pasta C:/Unit/NFe/arquivos/
Porém quando eu abro o arquivo .zip os arquivos ficam dentro de uma pasta C:/Unit/NFe/arquivos/ DENTRO DO ZIP.
Gostaria de saber como deichar os arquivos soltos dentro do arquivo zip.
[code]/*
- To change this template, choose Tools | Templates
- and open the template in the editor.
*/
package Classes;
import java.io.;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.zip.;
public class CompactarZip {
public static String compactar(ArrayList arquivos,Calendar x1,Calendar x2) {
// nome do arquivo que será compactado
// Cria um buffer para ler os dados do arquivo
byte[] buf = new byte[1024];
String compac="";
try {
// Cria o arquivo zip
compac = "C:/Unit/NFe/NFe_"+x1.get(Calendar.DAY_OF_MONTH)+"-"+(x1.get(Calendar.MONTH)+1)+"-"+x1.get(Calendar.YEAR)+"_"+x2.get(Calendar.DAY_OF_MONTH)+"-"+(x2.get(Calendar.MONTH)+1)+"-"+x2.get(Calendar.YEAR)+".zip";
ZipOutputStream out = new ZipOutputStream(new FileOutputStream(compac));
// Comprime o arquivo
FileInputStream in;
// Adiciona o arquivo ao fluxo de saída
for(int i=0;i<arquivos.size();i++){
in = new FileInputStream(arquivos.get(i).toString());
out.putNextEntry(new ZipEntry(arquivos.get(i).toString()));
// transfere dados do arquivo para o arquivo zip
int len;
while ((len = in.read(buf)) > 0) {
out.write(buf, 0, len);
}
// Finaliza a entrada
out.closeEntry();
in.close();
}
// Completa o arquivo zip
out.close();
} catch (IOException e) {
// possíveis erros aqui
}
return compac;
}
}[/code]