Commit fc664003 authored by Quxl's avatar Quxl
parents 6367ce00 172dc0ae
...@@ -136,12 +136,47 @@ public final class ZipUtil { ...@@ -136,12 +136,47 @@ public final class ZipUtil {
} }
} }
} }
public static void unzip1(File file, String descDir) {
ZipFile zipFile = null;
ZipInputStream zis = null;
try {
zipFile = new ZipFile(file);
zis = new ZipInputStream(new FileInputStream(file));
ZipEntry entry = null;
zis.getNextEntry(); // 删了就没法解压
while((entry = zis.getNextEntry()) != null && !entry.isDirectory()) {
InputStream is = zipFile.getInputStream(entry);
String fileName = descDir + File.separator + entry.getName();
File new_file = new File(fileName); //存在则删除
if(new_file.exists()) {
new_file.delete();
}
FileUtil.streamToFile(is, fileName);
}
} catch (Exception e) {
throw new ZipUtilException(e);
} finally {
try {
if(zipFile != null) {
zipFile.close();
}
if(zis != null) {
zis.close();
}
} catch (Exception e) {
throw new ZipUtilException(e);
}
}
}
public static void main(String[] args) { public static void main(String[] args) {
String targetPath = "D:\\data\\erp\\91310114594794273Y"; /*String targetPath = "D:\\data\\erp\\91330110MA2B16CL0G";
File file = ZipUtil.zip(targetPath); File file = ZipUtil.zip(targetPath);
System.out.println(file.getName()); System.out.println(file.getName()); */
//ZipUtil.unzip(file, "D:\\data\\erp\\91310114594794273Y"); File file = new File("C:\\Users\\zhangyong\\Desktop\\excel\\[7777]2021-01-14.zip");
ZipUtil.unzip(file, "C:\\Users\\zhangyong\\Desktop\\excel\\");
} }
} }
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment