From 9b1c48e0aadf587a104daa144dbb9f070b3d35b2 Mon Sep 17 00:00:00 2001
From: tangzy <tangzy123456>
Date: Thu, 25 Nov 2021 14:38:02 +0800
Subject: [PATCH] 1.统计

---
 src/main/java/org/springblade/modules/FTP/FtpUtil.java |   55 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 55 insertions(+), 0 deletions(-)

diff --git a/src/main/java/org/springblade/modules/FTP/FtpUtil.java b/src/main/java/org/springblade/modules/FTP/FtpUtil.java
index c0ba7ec..d5540d1 100644
--- a/src/main/java/org/springblade/modules/FTP/FtpUtil.java
+++ b/src/main/java/org/springblade/modules/FTP/FtpUtil.java
@@ -6,10 +6,12 @@
 import org.apache.commons.net.ftp.FTP;
 import org.apache.commons.net.ftp.FTPClient;
 import org.apache.commons.net.ftp.FTPReply;
+import org.springframework.web.multipart.MultipartFile;
 
 import java.io.*;
 import java.net.SocketException;
 import java.util.Date;
+import net.lingala.zip4j.core.ZipFile;
 
 import static org.springblade.common.config.FtpConfig.*;
 
@@ -302,5 +304,58 @@
 		}
 		FtpUtil.uploadFile(ftpHost, ftpPort, ftpUserName, ftpPassword, ftpPath, "/",  "n"+response1+".json", in1);
 	}
+	/**
+	 *
+	 * 解压zip 包
+	 * @author panchaoyuan
+	 * @param srcFile    Unzipped file
+	 * @param destDirPath   Unzipped destination folder
+	 * @throws RuntimeException
+	 * @throws IOException
+	 */
+	public static void unZip(MultipartFile srcFile, String destDirPath, String savePath) throws RuntimeException, IOException {
+		File file = null;
+		InputStream ins = srcFile.getInputStream();
+		String savaPaths = savePath+srcFile.getOriginalFilename();
+		file=new File(savaPaths);
+		inputStreamToFile(ins, file);
+
+		if (!file.exists()) {
+			throw new RuntimeException(file.getPath() + ",file is not found");
+		}
+		ZipFile zipFile = null;
+		try {
+			zipFile = new ZipFile(file);
+//			zipFile.setFileNameCharset("utf-8");
+			zipFile.setFileNameCharset("gbk");
+			//解压到 destDirPath
+			zipFile.extractAll(destDirPath);
+		}catch(Exception e) {
+			throw new RuntimeException("unzip error from FileUtil", e);
+		}
+	}
+
+
+	/**
+	 * 输入流转换为文件
+	 * @author panchaoyuan
+	 * @return
+	 */
+	private static void inputStreamToFile(InputStream ins, File file) {
+		try {
+			OutputStream os = new FileOutputStream(file);
+			int bytesRead = 0;
+			byte[] buffer = new byte[8192];
+			while ((bytesRead = ins.read(buffer, 0, 8192)) != -1) {
+				os.write(buffer, 0, bytesRead);
+			}
+			os.close();
+			ins.close();
+		}catch(Exception e) {
+			e.printStackTrace();
+		}
+	}
+
+
 
 }

--
Gitblit v1.9.3