Java 中读取配置文件的工具类封装:
public class PropertiesUtil {
public static Properties prop = null;
static {
prop = new Properties();
try {
File file = ResourceUtils.getFile("classpath:config.properties");
prop = PropertiesLoaderUtils.loadProperties(new FileSystemResource(file));
} catch (IOException e) {
e.printStackTrace();
}
}
public static String getValue(String key) {
return prop.getProperty(key);
}
}