hotfix-----windows导入大屏乱码问题

Raod 3 years ago
parent 6fd713cc50
commit 8bea4e8a59

@ -8,6 +8,7 @@ import org.springframework.web.multipart.MultipartFile;
import java.io.*; import java.io.*;
import java.net.URL; import java.net.URL;
import java.nio.channels.FileChannel; import java.nio.channels.FileChannel;
import java.nio.charset.StandardCharsets;
import java.nio.file.*; import java.nio.file.*;
import java.nio.file.attribute.BasicFileAttributes; import java.nio.file.attribute.BasicFileAttributes;
import java.util.Enumeration; import java.util.Enumeration;
@ -116,9 +117,11 @@ public class FileUtil {
*/ */
public static String readFile(File file) { public static String readFile(File file) {
BufferedReader reader = null; BufferedReader reader = null;
InputStreamReader isr = null;
StringBuilder sbf = new StringBuilder(); StringBuilder sbf = new StringBuilder();
try { try {
reader = new BufferedReader(new FileReader(file)); isr = new InputStreamReader(new FileInputStream(file), StandardCharsets.UTF_8);
reader = new BufferedReader(isr);
String tempStr; String tempStr;
while ((tempStr = reader.readLine()) != null) { while ((tempStr = reader.readLine()) != null) {
sbf.append(tempStr); sbf.append(tempStr);
@ -129,6 +132,13 @@ public class FileUtil {
log.error("读文件失败", e); log.error("读文件失败", e);
throw BusinessExceptionBuilder.build(ResponseCode.FAIL_CODE, e.getMessage()); throw BusinessExceptionBuilder.build(ResponseCode.FAIL_CODE, e.getMessage());
} finally { } finally {
if (null != isr) {
try {
isr.close();
} catch (IOException e) {
throw BusinessExceptionBuilder.build(ResponseCode.FAIL_CODE, e.getMessage());
}
}
if (reader != null) { if (reader != null) {
try { try {
reader.close(); reader.close();

Loading…
Cancel
Save