使用ClassPathResource读取resource下的文件
目录结构
文件读取代码
ClassPathResource classPathResource = new ClassPathResource("druid-datasource.properties");
Properties druidDatasource = new Properties();
InputStream inputStream = null;
try {
inputStream = classPathResource.getInputStream();
druidDatasource.load(inputStream);
} catch (IOException e) {
e.printStackTrace();
} finally {
if (inputStream != null) {
try {
inputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}