作者:sddfdffwfefe_863 | 来源:互联网 | 2023-02-07 00:45
我有一个int[]
输入的方法.
methodABC(int[] nValue)
我想从Java属性文件中获取此nValue
nValue=1,2,3
如何从配置文件中读取此内容,还是以其他格式存储?
我尝试的是(changing the nValue to 123 instead of 1,2,3
):
int nValue = Integer.parseInt(configuration.getProperty("nnValue"));
我们如何做到这一点?
1> ΦXocę 웃 Пepe..:
原始属性文件是如此90的:)你应该使用json文件,
无论如何:
如果你有这个:
nValue=1,2,3
然后读取nValue,将其拆分为逗号并将流/循环解析为int
例:
String property = prop.getProperty("nValue");
System.out.println(property);
String[] x = property.split(",");
for (String string : x) {
System.out.println(Integer.parseInt(string));
}
从java 8开始:
int[] values = Stream.of(property.split(",")).mapToInt(Integer::parseInt).toArray();
for (int i : values) {
System.out.println(i);
}