Java 中什么是配置文件
Java中的配置文件名称一般都以“.properties”和“.xml”进行结尾,这些配置文件的结构都和Java的HashMap结构是一样的,其作用是通过修改配置文件来实现代码中的参数的更改,从而实现灵活变更参数。
properties使用driver=com.mysql.jdbc.Driver
jdbcUrl=jdbc:mysql://localhost:3306/user
user=root
password=123456/**
* 读取config.properties文件中的内容,放到Properties类中
* @param filePath 文件路径
* @param key 配置文件中的key
* @return 返回key对应的value
*/
public static String readConfigFiles(String filePath,String key) {
Properties prop = new Properties();
try{
InputStream inputStream = new FileInputStream(filePath);
prop.load(inputStream);
inputStream.close();
return prop.get