Pārlūkot izejas kodu

zip解压添加编码格式

user5 4 gadi atpakaļ
vecāks
revīzija
9bb93fca34

+ 8 - 3
src/main/java/com/jeeplus/modules/ruralprojectrecords/service/SubProjectInfoService.java

@@ -28,6 +28,7 @@ import org.springframework.web.multipart.MultipartFile;
 
 import java.io.*;
 import java.net.URI;
+import java.nio.charset.Charset;
 import java.util.*;
 import java.util.zip.ZipEntry;
 import java.util.zip.ZipFile;
@@ -243,8 +244,9 @@ public class SubProjectInfoService extends CrudService<SubProjectInfoDao, SubPro
     @Transactional(readOnly = false)
     public Integer subProjectFileManage(SubProjectInfo subProjectInfo,String destDirPath){
         Integer result = 0;
+        File file = null;
         try {
-            File file = new File(destDirPath);
+            file = new File(destDirPath);
             File[] files = file.listFiles();
             Arrays.sort(files);
             if(files.length > 1){
@@ -304,11 +306,12 @@ public class SubProjectInfoService extends CrudService<SubProjectInfoDao, SubPro
                         }
                     }
                 }
-                deleteAllFilesOfDir(file);
             }
 
         }  catch (Exception e) {
             e.printStackTrace();
+        }finally {
+            deleteAllFilesOfDir(file);
         }
         return result;
     }
@@ -495,7 +498,9 @@ public class SubProjectInfoService extends CrudService<SubProjectInfoDao, SubPro
         // 开始解压
         ZipFile zipFile = null;
         try {
-            zipFile = new ZipFile(file);
+            //zipFile = new ZipFile(file);
+            //添加解压编码,解决解压报错问题
+            zipFile = new ZipFile(file, Charset.forName("GBK"));
             Enumeration<?> entries = zipFile.entries();
             while (entries.hasMoreElements()) {
                 ZipEntry entry = (ZipEntry) entries.nextElement();