Java获取自定义配置文件的内容
在resources目录下定义db.properties文件
driverClassName=com.mysql.jdbc.Driver
url=jdbc:mysql:////jdbcdemo
username=root
password=root
获取文件信息:
public static void main(String[] args) throws IOException {
ClassLoader loader = Thread.currentThread().getContextClassLoader();
InputStream resourceAsStream = loader.getResourceAsStream("db.properties");
Properties p = new Properties();
p.load(resourceAsStream);
System.out.println(p.getProperty("driverClassName"));
}