一、引入依赖
<dependency>
<groupId>cn.hutool</groupId>
<artifactId>hutool-all</artifactId>
<version>5.3.5</version>
</dependency>
二、直接读取返回
public String getContent(String path){
try {
File file = ResourceUtils.getFile("classpath:"+path); //获取项目路径中的文件
return FileReader.create(file).readString(); //读取字符串
} catch (FileNotFoundException e) {
throw new RuntimeException(e);
}
}