Bladeren bron

3.4.6 20250613 测试下载文件名乱码

xiaofei 1 week geleden
bovenliggende
commit
692ac77117

+ 0 - 3
teachcloud-common/src/main/java/com/qmth/teachcloud/common/util/Zip4jUtil.java

@@ -175,9 +175,6 @@ public class Zip4jUtil {
                 zipFile = new ZipFile(scrPath);
             }
 
-            // 防止中文文件名乱码
-            zipFile.setCharset(java.nio.charset.StandardCharsets.UTF_8);
-
             ZipParameters parameters = new ZipParameters();
             // 压缩方法
             parameters.setCompressionMethod(CompressionMethod.DEFLATE);

+ 10 - 4
teachcloud-mark/src/main/java/com/qmth/teachcloud/mark/service/impl/MarkStudentServiceImpl.java

@@ -85,6 +85,10 @@ import java.lang.reflect.Field;
 import java.math.BigDecimal;
 import java.net.URLEncoder;
 import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.nio.file.StandardOpenOption;
 import java.util.List;
 import java.util.*;
 import java.util.stream.Collectors;
@@ -1533,10 +1537,12 @@ public class MarkStudentServiceImpl extends ServiceImpl<MarkStudentMapper, MarkS
             log.debug("导出Excel开始...");
             ExcelWriter writer = ExcelWriter.create(ExcelType.XLSX);
             writer.writeDataArrays("成绩单", null, columnNames, columnValues.listIterator());
-            FileOutputStream fileOut = new FileOutputStream(downloadFilePath + File.separator + basicCourse.getName() + "-成绩单" + SystemConstant.EXCEL_PREFIX);
-            writer.output(fileOut);
-            fileOut.flush();
-            fileOut.close();
+//            FileOutputStream fileOut = new FileOutputStream(downloadFilePath + File.separator + basicCourse.getName() + "-成绩单" + SystemConstant.EXCEL_PREFIX);
+            Path filePath = Paths.get(downloadFilePath, basicCourse.getName() + "-成绩单" + SystemConstant.EXCEL_PREFIX);
+            OutputStream outputStream = Files.newOutputStream(filePath, StandardOpenOption.CREATE, StandardOpenOption.WRITE);
+            writer.output(outputStream);
+            outputStream.flush();
+            outputStream.close();
 
             // 通过教学班聚合
             Map<Object, List<CellValue[]>> listMap = columnValues.stream().collect(Collectors.groupingBy(m -> getCellValueFieldValue("value", m[3])));