Properties props = new Properties();
InputStream inputStream = Config.class.getResourceAsStream("/resourece/jdbc.properties");
props.load(inputStream);
System.err.println(props.getProperty("jdbc.url"));
本文展示了一个使用Java读取配置文件并打印出特定属性值的例子。通过创建Properties对象,并利用类路径获取资源流的方式加载配置文件,最后通过getProperty方法获取指定键对应的值。
Properties props = new Properties();
InputStream inputStream = Config.class.getResourceAsStream("/resourece/jdbc.properties");
props.load(inputStream);
System.err.println(props.getProperty("jdbc.url"));

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