Maven项目中,读取properties配置文件。
(1)properties文件在src/main/java的根目录中时加载文件使用:PropertyConfigurator.configure("log4j.properties");
(2)properties文件不在src/main/java的根目录中时:
使用的加载方式是:XXX.class.getClassLoader().getResourceAsStream("log4j.properties");
否则报错:找不到指定文件
og4j:ERROR Could not read configuration file [log4j.properties].
java.io.FileNotFoundException: log4j.properties (系统找不到指定的文件。)
at java.io.FileInputStream.open0(Native Method)
at java.io.FileInputStream.open(FileInputStream.java:195)
at java.io.FileInputStream.<init>(FileInputStream.java:138)
at java.io.FileInputStream.<init>(FileInputStream.java:93)
at org.apache.log4j.PropertyConfigurator.doConfigure(PropertyConfigurator.java:372)
at org.apache.log4j.PropertyConfigurator.configure(PropertyConfigurator.java:403)
at yibai.com.app.APP.main(APP.java:22)
log4j:ERROR Ignoring configuration file [log4j.properties].