Consegui compactar o arquivo sem problemas porem,nao quero que ao extrair o mesmo o diretorio to seja copiado.
ex:nome do diretorio q ira ser compactado="c:/desktop/texto.txt
quero que na hora de extrair eu escolha o diretorio e nao que venha igual ao q foi compactado.
public static ZipFile compactaArquivo( String diretorio ) {
// Create a buffer for reading the files
byte[] buf = new byte[1024];
try {
// Create the ZIP file
FileInputStream fileInputStream = new FileInputStream(diretorio);
String diretorioZip = diretorio+".zip";
ZipOutputStream zipOutputStream = new ZipOutputStream(new FileOutputStream(diretorioZip));
// Compress the files
// Add ZIP entry to output stream.
zipOutputStream.putNextEntry(new ZipEntry(diretorio));
// Transfer bytes from the file to the ZIP file
int len;
while ((len = fileInputStream.read(buf)) > 0) {
zipOutputStream.write(buf, 0, len);
}
// Complete the entry
zipOutputStream.closeEntry();
fileInputStream.close();
// Complete the ZIP file
zipOutputStream.close();
return new ZipFile(diretorioZip);
} catch (Exception e) {
new MakingError("(compactaArquivo):Erro ao zipar o arquivo "+e.getMessage(), e);
return null;
}
}