1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
// 要放入临时文件的文件夹路径
String tempStr = AllTest.class.getResource("/").getPath() + "temp";
// 使用uuid,不覆盖
File tempFile;
try {
tempFile = File.createTempFile(tempStr + UUID.randomUUID(), ".txt");
} catch (IOException e) {
log.error("创建临时文件失败", e);
throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR, "创建临时文件失败", e);
}
// 会覆盖
File tempFile;
try {
tempFile = File.createTempFile(tempStr + "demo", ".txt");
} catch (IOException e) {
log.error("创建临时文件失败", e);
throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR, "创建临时文件失败", e);
}
|