public static void unzip(String zipFilePath, String destDir) throws IOException{
try(ZipFile file = new ZipFile(zipFilePath))
{
FileSystem fileSystem = FileSystems.getDefault();
//Get file entries
Enumeration<? extends ZipEntry> entries = file.entries();
//We will unzip files in this folder
String uncompressedDirectory = destDir;
Files.createDirectory(fileSystem.getPath(uncompressedDirectory));
//Iterate over entries
while (entries.hasMoreElements())
{
ZipEntry entry = entries.nextElement();
//If directory then create a new directory in uncompressed folder
if (entry.isDirectory())
{
int h=entry.getName().indexOf('/');
String e=entry.getName().substring(h);
System.out.println("Creating Directory:" + uncompressedDirectory + e);
Files.createDirectories(fileSystem.getPath(uncompressedDirectory + e));
}
//Else create the file
else
{
InputStream is = file.getInputStream(entry);
BufferedInputStream bis = new BufferedInputStream(is);
int h=entry.getName().indexOf('/');
String e=entry.getName().substring(h);
String uncompressedFileName = uncompressedDirectory + e;
Path uncompressedFilePath = fileSystem.getPath(uncompressedFileName);
Files.createFile(uncompressedFilePath);
FileOutputStream fileOutput = new FileOutputStream(uncompressedFileName);
while (bis.available() > 0)
{
fileOutput.write(bis.read());
}
fileOutput.close();
System.out.println("Written :" + entry.getName());
}
}
file.close();
File f = new File(zipFilePath);
f.delete();
log.info("Se ha realizado la descompresion de la nueva version");
}
catch(IOException e)
{
e.printStackTrace();
}
}
I would like if there is some part of the code that can be changed to decompress zips faster. The problem is that I have to decompress zips of more than 20 MB and it takes each of them like 5 or 6 minutes.