中文乱码

This commit is contained in:
qiminbao
2025-10-28 17:34:59 +08:00
parent 72af737163
commit 1a58e37e7c
@@ -27,9 +27,8 @@ import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.io.File; import java.io.*;
import java.io.IOException; import java.nio.charset.StandardCharsets;
import java.io.InputStream;
import java.nio.file.*; import java.nio.file.*;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.*; import java.util.*;
@@ -1021,17 +1020,14 @@ public class AgentServiceImpl implements AgentService {
} }
} }
Properties props = new Properties(); Properties props = new Properties();
try (InputStream input = Files.newInputStream(path)) { try (InputStreamReader reader = new InputStreamReader(new FileInputStream(filePath), StandardCharsets.UTF_8)) { // 明确指定 UTF-8 编码
// 加载配置文件 props.load(reader);
props.load(input);
result = props.getProperty("logicalNode", ""); result = props.getProperty("logicalNode", "");
System.out.println("配置文件加载成功");
GlobalConfig.LOGICAL_NODE_LAST_TIME = lastTime; GlobalConfig.LOGICAL_NODE_LAST_TIME = lastTime;
GlobalConfig.LOGICAL_NODE = result; GlobalConfig.LOGICAL_NODE = result;
} catch (IOException e) { } catch (IOException e) {
System.err.println("无法加载配置文件,使用默认值"); System.err.println("读取文件失败: " + e.getMessage());
} catch (NumberFormatException e) { e.printStackTrace();
System.err.println("配置文件格式错误: " + e.getMessage());
} }
return result; return result;
} }