3/24 读取文件优化1.0

dev
wangwei 2 weeks ago
parent 21c9c62cf4
commit c75f0ebee8

@ -40,6 +40,7 @@ import org.springframework.web.client.RestTemplate;
import javax.annotation.Resource; import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import java.io.BufferedReader;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.io.FileReader; import java.io.FileReader;
import java.io.IOException; import java.io.IOException;
@ -268,19 +269,15 @@ public class SpsSyncDataController {
private String readDataFile(String cacheFilePath) { private String readDataFile(String cacheFilePath) {
// 读取文件数据 // 读取文件数据
try { try (BufferedReader reader = new BufferedReader(new FileReader(cacheFilePath))) {
FileReader reader = new FileReader(cacheFilePath); StringBuilder str = new StringBuilder(1024);
StringBuilder str = new StringBuilder(); String line;
int data; while ((line = reader.readLine()) != null) {
while ((data = reader.read()) != -1) { str.append(line);
str.append((char) data); }
}
reader.close();
return str.toString(); return str.toString();
} catch (FileNotFoundException e) { } catch (IOException e) { // 3. 合并异常处理
throw new RuntimeException("系统异常,未找到对应数据文件"); throw new RuntimeException("文件读取失败: " + e.getMessage(), e);
} catch (IOException e) {
throw new RuntimeException(e);
} }
} }

Loading…
Cancel
Save