|
@@ -348,19 +348,18 @@ public class GoodsController {
|
|
|
String newFilePath = filePath + fileName;
|
|
|
File zipFile = new File(newFilePath);
|
|
|
unZipFiles(zipFile, path,list,type);//解压文件,获取文件路径
|
|
|
- } catch (IOException e) {
|
|
|
+ } catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
- System.out.println("解压执行失败");
|
|
|
+ logger.info("解压执行失败");
|
|
|
throw e;
|
|
|
+ }finally {
|
|
|
+ //程序结束时,删除临时文件
|
|
|
+ deleteFiles(filePath);//删除压缩包文件夹
|
|
|
+ deleteFiles(path);//删除解压文件夹**
|
|
|
}
|
|
|
|
|
|
-
|
|
|
logger.info(JSON.toJSONString(list));
|
|
|
- //程序结束时,删除临时文件
|
|
|
- deleteFiles(filePath);//删除压缩包文件夹
|
|
|
- deleteFiles(path);//删除解压文件夹**
|
|
|
-
|
|
|
- Map<String, Object> jsonMap = new HashMap<String, Object>();
|
|
|
+ Map<String, Object> jsonMap = new HashMap<>();
|
|
|
jsonMap.put("ret",list);
|
|
|
return jsonMap;
|
|
|
}
|
|
@@ -393,17 +392,14 @@ public class GoodsController {
|
|
|
|
|
|
public void unZipFiles(File srcFile, String destDirPath, List<String> list, int type) throws RuntimeException {
|
|
|
long start = System.currentTimeMillis();
|
|
|
+ ZipFile zipFile = null;
|
|
|
+ try {
|
|
|
// 判断源文件是否存在
|
|
|
if (!srcFile.exists()) {
|
|
|
throw new RuntimeException(srcFile.getPath() + "所指文件不存在");
|
|
|
}
|
|
|
// 开始解压
|
|
|
- ZipFile zipFile = null;
|
|
|
- try {
|
|
|
- zipFile = new ZipFile(srcFile);
|
|
|
- } catch (IOException e) {
|
|
|
- throw new RRException("zip文件解压出错", e);
|
|
|
- }
|
|
|
+ zipFile = new ZipFile(srcFile);
|
|
|
zipFile.getEncoding();
|
|
|
Enumeration<?> entries = zipFile.getEntries();
|
|
|
List<ZipEntry> entryList = new ArrayList<>();
|
|
@@ -413,13 +409,12 @@ public class GoodsController {
|
|
|
entryList.add(entry);
|
|
|
// 如果是文件夹,就创建个文件夹
|
|
|
}
|
|
|
- if(null==entryList){
|
|
|
- throw new RRException("文件夹内无图片信息,请检查后重试");
|
|
|
- }
|
|
|
- if(entryList.size()>30){
|
|
|
- throw new RRException("最多上传30张图片");
|
|
|
- }
|
|
|
- try {
|
|
|
+ if(null==entryList){
|
|
|
+ throw new RRException("文件夹内无图片信息,请检查后重试");
|
|
|
+ }
|
|
|
+ if(entryList.size()>30){
|
|
|
+ throw new RRException("最多上传30张图片");
|
|
|
+ }
|
|
|
for(ZipEntry entry : entryList){
|
|
|
if (entry.isDirectory()) {
|
|
|
String dirPath = destDirPath + "/" + entry.getName();
|