1、文件读取
String filePath = "templates/demo.txt";
ClassPathResource resource = new ClassPathResource(filePath);
if (resource.exists()) {
try (BufferedReader reader = new BufferedReader(new InputStreamReader(resource.getInputStream()))) {
String tempString;
while ((tempString = reader.readLine()) != null) {
}
} catch (IOException e) {
e.printStackTrace();
}
}
注意点: resource.getFile()读取文件由于系统差异,在linux中使用时无法读取;推荐使用 resource.getInputStream()