better directory handling
This commit is contained in:
parent
4fde0f20cc
commit
5c6f2bbbcb
|
@ -10,15 +10,18 @@ import java.util.zip.ZipInputStream;
|
||||||
public class FileUtil {
|
public class FileUtil {
|
||||||
public static final String RUSEFI_SETTINGS_FOLDER = System.getProperty("user.home") + File.separator + ".rusEFI";
|
public static final String RUSEFI_SETTINGS_FOLDER = System.getProperty("user.home") + File.separator + ".rusEFI";
|
||||||
|
|
||||||
public static void unzip(String zipFileName, String destPath) throws IOException {
|
public static void unzip(String zipFileName, File destDir) throws IOException {
|
||||||
File destDir = new File(destPath);
|
|
||||||
byte[] buffer = new byte[1024];
|
byte[] buffer = new byte[1024];
|
||||||
ZipInputStream zis = new ZipInputStream(new FileInputStream(zipFileName));
|
ZipInputStream zis = new ZipInputStream(new FileInputStream(zipFileName));
|
||||||
ZipEntry zipEntry = zis.getNextEntry();
|
ZipEntry zipEntry = zis.getNextEntry();
|
||||||
while (zipEntry != null) {
|
while (zipEntry != null) {
|
||||||
File newFile = newFile(destDir, zipEntry);
|
File newFile = newFile(destDir, zipEntry);
|
||||||
if (newFile.isDirectory()) {
|
if (zipEntry.isDirectory()) {
|
||||||
System.out.println("Nothing to do for directory " + newFile);
|
if (!newFile.isDirectory()) {
|
||||||
|
// we already have a file with name matching directory name
|
||||||
|
newFile.delete();
|
||||||
|
}
|
||||||
|
newFile.mkdirs();
|
||||||
} else {
|
} else {
|
||||||
unzipFile(buffer, zis, newFile);
|
unzipFile(buffer, zis, newFile);
|
||||||
}
|
}
|
||||||
|
@ -26,7 +29,7 @@ public class FileUtil {
|
||||||
}
|
}
|
||||||
zis.closeEntry();
|
zis.closeEntry();
|
||||||
zis.close();
|
zis.close();
|
||||||
System.out.println("Unzip " + zipFileName + " to " + destPath + " worked!");
|
System.out.println("Unzip " + zipFileName + " to " + destDir + " worked!");
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void unzipFile(byte[] buffer, ZipInputStream zis, File newFile) throws IOException {
|
private static void unzipFile(byte[] buffer, ZipInputStream zis, File newFile) throws IOException {
|
||||||
|
|
Loading…
Reference in New Issue