文本文件编码默认UTF-8输出到页面

This commit is contained in:
chenkailing 2020-12-28 23:56:38 +08:00
parent c66dda239f
commit 92869e8d6c

View File

@ -12,6 +12,7 @@ import org.springframework.util.Base64Utils;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.nio.charset.StandardCharsets;
/** /**
* Created by kl on 2018/1/17. * Created by kl on 2018/1/17.
@ -36,8 +37,8 @@ public class SimTextFilePreviewImpl implements FilePreview {
try { try {
File originFile = new File(response.getContent()); File originFile = new File(response.getContent());
String charset = KkFileUtils.getFileEncode(originFile); String charset = KkFileUtils.getFileEncode(originFile);
String xmlString = FileUtils.readFileToString(originFile, charset); String fileData = FileUtils.readFileToString(originFile, charset);
model.addAttribute("textData", Base64Utils.encodeToString(xmlString.getBytes(charset))); model.addAttribute("textData", Base64Utils.encodeToString(fileData.getBytes(StandardCharsets.UTF_8)));
} catch (IOException e) { } catch (IOException e) {
return otherFilePreview.notSupportedFile(model, fileAttribute, e.getLocalizedMessage()); return otherFilePreview.notSupportedFile(model, fileAttribute, e.getLocalizedMessage());
} }