Properties类读取properties配置文件
<h5>通过Properties类读取properties文件内容</h5>
<pre><code>package com.example.demo.proper;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
/**
* 测试通过Properties类
*
* @author jxd
* @version 1.0 *
* @date 2021/1/13 9:35
*/
public class TestProperties {
public static void main(String[] args) throws Exception {
Pro pro = new TestProperties().new Pro();
Properties p = pro.rtnProperties();
System.out.println(p.getProperty("ceshi.age"));
System.out.println(p.getProperty("ceshi.address"));
}
class Pro {
/**
* 测试通过Properties类读取配置文件
*/
public Properties rtnProperties() throws IOException {
InputStream stm = this.getClass().getClassLoader().getResourceAsStream("jinxudong.properties");
Properties properties = new Properties();
properties.load(stm);
return properties;
}
}
}
</code></pre>