thinkuncle / thinkuncle.github.io

thinkuncle
4 stars 0 forks source link

jar读取内部和外部配置文件 #133

Open thinkuncle opened 7 years ago

thinkuncle commented 7 years ago

方法1

读取properties文件方法

InputStream ins = getClass().getResourceAsStream("/resource/dbconfig.properties");

log4j.xml 需要单独处理

PropertyConfigurator.configure(System.getProperty("user.dir") + "/resource/log4j.xml"); 

方法二:

配置文件out.properties和jiar包在同一个目录下面:

FileInputStream inputStream1 = new FileInputStream("out.properties");  

配置文件in.properties在jar包内部:

InputStream inputStream2 = a.class.getResourceAsStream("/in.properties");