InputStream inputStream = this.getClass().getClassLoader().getResourceAsStream("ipConfig.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"));
Properties p = new Properties();
try {
p.load(inputStream);
} catch (IOException e1) {
e1.printStackTrace();
}
System.out.println("ip:"+p.getProperty("ip")+",port:"+p.getProperty("port"));
本文介绍了一个简单的Java程序示例,展示了如何使用InputStream和Properties类从资源文件中加载属性设置。通过此方法可以方便地从外部配置文件中读取如IP地址和端口号等配置信息。
1万+

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



