IDEA
项目机构如图:
测试代码:
public class TestUtil {
public static void main(String[] args) {
Properties properties = new Properties();
InputStream resourceAsStream = TestUtil.class.getResourceAsStream("/showtime.properties");
try {
properties.load(resourceAsStream);
System.out.println(properties.getProperty("redis.ip"));
} catch (IOException e) {
e.printStackTrace();
}
System.out.println("========");
InputStream inputStream = TestUtil.class.getClassLoader().getResourceAsStream("showtime.properties");
try {
properties.load(inputStream);
System.out.println(properties.getProperty("redis.ip"));
} catch (IOException e) {
e.printStackTrace();
}
}
}
运行结果:
195.122.125.112
========
195.122.125.112