在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"));
}
原文:https://www.cnblogs.com/snail-gao/p/14665120.html