Browse Source

!75 修复xlsx7.4以上版本 乱码
Merge pull request !75 from 高雄/master

kailing 2 years ago
parent
commit
3e2e330fcb
1 changed files with 4 additions and 5 deletions
  1. 4 5
      server/src/main/java/cn/keking/service/FileHandlerService.java

+ 4 - 5
server/src/main/java/cn/keking/service/FileHandlerService.java

@@ -5,13 +5,13 @@ import cn.keking.model.FileAttribute;
 import cn.keking.model.FileType;
 import cn.keking.service.cache.CacheService;
 import cn.keking.service.cache.NotResourceCache;
+import cn.keking.utils.EncodingDetects;
 import cn.keking.utils.KkFileUtils;
 import cn.keking.utils.WebUtils;
 import com.aspose.cad.CodePages;
 import com.aspose.cad.Color;
 import com.aspose.cad.Image;
 import com.aspose.cad.LoadOptions;
-import com.aspose.cad.fileformats.cad.CadDrawTypeMode;
 import com.aspose.cad.imageoptions.CadRasterizationOptions;
 import com.aspose.cad.imageoptions.PdfOptions;
 import org.apache.pdfbox.pdmodel.PDDocument;
@@ -41,8 +41,6 @@ import java.util.Map;
 public class FileHandlerService {
 
     private final Logger logger = LoggerFactory.getLogger(FileHandlerService.class);
-
-    private static final String DEFAULT_CONVERTER_CHARSET = System.getProperty("sun.jnu.encoding");
     private final String fileDir = ConfigConstants.getFileDir();
     private final CacheService cacheService;
 
@@ -142,9 +140,10 @@ public class FileHandlerService {
      * @param outFilePath 文件绝对路径
      */
     public void doActionConvertedFile(String outFilePath) {
+        String charset = EncodingDetects.getJavaEncode(outFilePath);
         StringBuilder sb = new StringBuilder();
         try (InputStream inputStream = new FileInputStream(outFilePath);
-             BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream, DEFAULT_CONVERTER_CHARSET))) {
+             BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream, charset))) {
             String line;
             while (null != (line = reader.readLine())) {
                 if (line.contains("charset=gb2312")) {
@@ -287,7 +286,7 @@ public class FileHandlerService {
             attribute.setSkipDownLoad(true);
         }
         url = WebUtils.encodeUrlFileName(url);
-       fileName =  KkFileUtils.htmlEscape(fileName);  //文件名处理
+        fileName =  KkFileUtils.htmlEscape(fileName);  //文件名处理
         attribute.setType(type);
         attribute.setName(fileName);
         attribute.setSuffix(suffix);