v1.1初始化

This commit is contained in:
qiminbao
2025-10-27 10:27:48 +08:00
parent 62c8736728
commit 1485d5d46c
11 changed files with 252 additions and 25 deletions
@@ -16,6 +16,7 @@ import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.temporal.ChronoUnit;
import java.util.*;
import java.util.stream.Collectors;
public class AgentUtil {
@@ -552,4 +553,31 @@ public class AgentUtil {
}
}
public static String getNetworkParam(String filePath, String key){
Properties props = new Properties();
String result = "";
try (InputStream input = Files.newInputStream(Paths.get(filePath))) {
// 加载配置文件
props.load(input);
result = props.getProperty(key, "");
System.out.println("配置文件加载成功");
} catch (IOException e) {
System.err.println("无法加载配置文件,使用默认值");
} catch (NumberFormatException e) {
System.err.println("配置文件格式错误: " + e.getMessage());
}
return result;
}
/**
* 读取文件,跳过空行,将所有非空行拼接成一个字符串
* @param filePath 文件路径
* @return 拼接后的字符串(空行已去除)
*/
public static String readNonEmptyLinesAsString(String filePath) throws Exception {
return Files.lines(Paths.get(filePath))
.filter(line -> !line.trim().isEmpty()) // 去除 null 和 空/空白行
.collect(Collectors.joining("\n")); // 用换行符连接
}
}