解决时间同步性解析文件中文乱码

master
dongpengju 4 months ago
parent f4a6476e1b
commit bc12bbfde5
  1. 11
      motor-system/src/main/java/com/motor/system/service/impl/StationMachineServiceImpl.java

@ -26,10 +26,8 @@ import org.springframework.util.CollectionUtils;
import org.springframework.util.ObjectUtils; import org.springframework.util.ObjectUtils;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
import java.io.BufferedReader; import java.io.*;
import java.io.File; import java.nio.charset.Charset;
import java.io.FileReader;
import java.io.IOException;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
import java.nio.file.Paths; import java.nio.file.Paths;
@ -341,7 +339,8 @@ public class StationMachineServiceImpl implements IStationMachineService {
BufferedReader reader; BufferedReader reader;
try { try {
StringBuilder content = new StringBuilder(); StringBuilder content = new StringBuilder();
reader = new BufferedReader(new FileReader(filePathName)); InputStreamReader isr = new InputStreamReader(new FileInputStream(filePathName), "UTF-8");
reader = new BufferedReader(isr);
String line = null; String line = null;
while ((line = reader.readLine()) != null) { while ((line = reader.readLine()) != null) {
content.append(line); content.append(line);
@ -350,7 +349,7 @@ public class StationMachineServiceImpl implements IStationMachineService {
strList.add(content); strList.add(content);
reader.close(); reader.close();
return strList; return strList;
} catch (IOException e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
System.out.println("文件不存在"); System.out.println("文件不存在");
return strList; return strList;

Loading…
Cancel
Save