写java的时候,有时候查到的数据暂时用不到,我们可以把它写到一个临时文件中。
今天写项目的时候发现了这个好方法。
将context的内容写到临时文件
@PostMapping("/temp")
@ResponseBody
String temp(@RequestParam String content) throws IOException {
File tempFile = Files.createTempFile(null, null).toFile();
FileCopyUtils.copy(content.getBytes(StandardCharsets.UTF_8), tempFile);
return tempFile.getName();
}
文件被存在这个路径下:C:\Users\my\AppData\Local\Temp
要用的时候再去取出来
json = Utils.tempFileContent(fileName);