思维导图:
我这边使用的是类加载器的方法,获取properties文件
案例代码如下:
PropertiesTest
package com.lbl.properties;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
public class PropertiesTest {
public static void main(String[] args) throws IOException {
Properties properties = new Properties();
InputStream property = PropertiesTest.class.getClassLoader().getResourceAsStream("resource.properties");
properties.load(property);
System.out.println(properties.getProperty("name"));
}
}
resource.properties
name=Carlos