55 lines
1.3 KiB
Java
55 lines
1.3 KiB
Java
/*
|
|
* Copyright (c) 2017 univento.eu - All rights reserved
|
|
* You are not allowed to use, distribute or modify this code
|
|
*/
|
|
|
|
package eu.univento.commons.utils;
|
|
|
|
import java.io.File;
|
|
import java.io.FileInputStream;
|
|
import java.io.FileOutputStream;
|
|
import java.io.IOException;
|
|
import java.util.zip.ZipEntry;
|
|
import java.util.zip.ZipInputStream;
|
|
|
|
/**
|
|
* @author joethei
|
|
* @version 1.0
|
|
*/
|
|
public class Files {
|
|
|
|
public static void unzip(File zipFile, File folder) {
|
|
byte[] buffer = new byte[1024];
|
|
|
|
try {
|
|
if (!folder.exists()) {
|
|
folder.mkdir();
|
|
}
|
|
|
|
ZipInputStream zis = new ZipInputStream(new FileInputStream(zipFile));
|
|
ZipEntry entry;
|
|
while ((entry = zis.getNextEntry()) != null) {
|
|
|
|
String fileName = entry.getName();
|
|
File newFile = new File(folder + File.separator + fileName);
|
|
|
|
new File(newFile.getParent()).mkdirs();
|
|
|
|
FileOutputStream fos = new FileOutputStream(newFile);
|
|
|
|
int len;
|
|
while ((len = zis.read(buffer)) > 0) {
|
|
fos.write(buffer, 0, len);
|
|
}
|
|
|
|
fos.close();
|
|
}
|
|
|
|
zis.closeEntry();
|
|
zis.close();
|
|
} catch (IOException ex) {
|
|
ex.printStackTrace();
|
|
}
|
|
}
|
|
|
|
} |