先看结果:
这里只是一个测试用例,文档里面的内容也是随便写的

文件的位置写在了yml文件里

后台代码:
java
//引入文件路径
@Vaule("${txt.path}")
private String filePath;
@GetMapping("/readTxt")
public AjaxResult readTxt() throws Exception{
File file = new File(filePath);
if (!file.exists()) {
throw new RuntimeException("文件不存在");
}
StringBuilder sb = new StringBuilder();
try (BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(file), StandardCharsets.UTF_8))) {
String line;
while ((line = br.readLine()) != null) {
sb.append(line).append(System.lineSeparator());
}
}
return AjaxResult.success(sb.toString());
}
前端代码:(测试demo,只展示调用,实际上应该在js中写方法,然后进入,最后调用)

结果:
