InputStream inputStream =test.class.getClassLoader().getResourceAsStream("abc.properties");
Properties p = new Properties();
try {
p.load(inputStream);
} catch (IOException e1) {
e1.printStackTrace();
}
System.out.println( " ip: " + p.getProperty("ip") + " ,port: " + p.getProperty("port"));
------------------abc.properties内容---------------------
ip=1
port=2
---------------------------------------------------------
Properties p = new Properties();
try {
p.load(inputStream);
} catch (IOException e1) {
e1.printStackTrace();
}
System.out.println( " ip: " + p.getProperty("ip") + " ,port: " + p.getProperty("port"));
------------------abc.properties内容---------------------
ip=1
port=2
---------------------------------------------------------
本文详细介绍了如何使用Java代码从abc.properties文件中加载配置,并成功提取了IP和端口号。
8万+

被折叠的 条评论
为什么被折叠?



