(1)如何用 Properties 类读取 .properties 文件?
Properties 类是 Hashtable 的子类,常用的方法有:
- load(InputStream inStream),load(Reader reader) 【读取文件】
- getProperty(String key) 【获取属性值】
- setProperty(String key, String value) 【设置属性值】
- store(OutputStream out, String comments),store(Writer writer, String comments) 【将该对象的属性列表存储到输出流中】
public static void main(String[] args) {
Properties properties = new Properties();
String filePath = "";//文件路径
try {
properties.load(new FileInputStream(filePath));