|
@@ -0,0 +1,37 @@
|
|
|
+package com.dskj.znzn.importData.executor.utils;
|
|
|
+
|
|
|
+import java.io.*;
|
|
|
+import java.util.zip.ZipEntry;
|
|
|
+import java.util.zip.ZipInputStream;
|
|
|
+
|
|
|
+public class UnzipFile {
|
|
|
+
|
|
|
+ public static void unzip(String zipFilePath, String destDirectory) {
|
|
|
+ try (ZipInputStream zipIn = new ZipInputStream(new FileInputStream(zipFilePath))) {
|
|
|
+ ZipEntry entry = zipIn.getNextEntry();
|
|
|
+ while (entry != null) {
|
|
|
+ String filePath = destDirectory + File.separator + entry.getName();
|
|
|
+ if (!entry.isDirectory()) {
|
|
|
+ extractFile(zipIn, filePath);
|
|
|
+ } else {
|
|
|
+ File dir = new File(filePath);
|
|
|
+ dir.mkdirs();
|
|
|
+ }
|
|
|
+ zipIn.closeEntry();
|
|
|
+ entry = zipIn.getNextEntry();
|
|
|
+ }
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private static void extractFile(ZipInputStream zipIn, String filePath) throws IOException {
|
|
|
+ try (BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(filePath))) {
|
|
|
+ byte[] bytesIn = new byte[4096];
|
|
|
+ int read = 0;
|
|
|
+ while ((read = zipIn.read(bytesIn)) != -1) {
|
|
|
+ bos.write(bytesIn, 0, read);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|