1、工具类
package com.lenovo.tdp.inbox.common.utils;
import org.springframework.util.StringUtils;
import org.springframework.web.multipart.MultipartFile;
import java.io.*;
import java.nio.charset.Charset;
import java.util.zip.ZipFile;
public class FileUtils {
public static ZipFile fileToZipFile(File file){
String fileName = file.getName();
String oldAppcode = "";
// 文件的校验
ZipFile zipFile = null;
try {
if (StringUtils.isEmpty(fileName) || !fileName.endsWith(".zip") || file == null || !file.exists()) {
throw new IOException();
}
zipFile = new ZipFile(file, Charset.forName("UTF-8"));
} catch (IOException e) {
File zipFileUrl = new File(fileName);
try {
org.apache.commons.io.FileUtils.delete(zipFileUrl);
} catch (IOException ioException) {
ioException.printStackTrace();
}
throw new RuntimeException("压缩包无法解析!");
}
return zipFile;
}
public static File multipartFileToFile(MultipartFile multipartFile, String filePath) throws IOException {
File file = null;
InputStream inputStream = null;
OutputStream outputStream = null;
try {
inputStream = multipartFile.getInputStream();
file = new File(filePath);
outputStream = new FileOutputStream(file);
write(inputStream, outputStream);
} catch (IOException e) {