如何在java中创建一个临时文件,而不在文件名后面附加随机数?
2022-08-31 20:55:02
我需要创建一个临时文件,所以我尝试了这个:
String[] TempFiles = {"c1234c10","c1234c11","c1234c12","c1234c13"};
for (int i = 0; i <= 3; i++) {
try {
String tempFile = TempFiles[i];
File temp = File.createTempFile(tempFile, ".xls");
System.out.println("Temp file : " + temp.getAbsolutePath());
} catch (IOException e) {
e.printStackTrace();
}
}
输出如下所示:
Temp file : C:\Users\MD1000\AppData\Local\Temp\c1234c108415816200650069233.xls
Temp file : C:\Users\MD1000\AppData\Local\Temp\c1234c113748833645638701089.xls
Temp file : C:\Users\MD1000\AppData\Local\Temp\c1234c126104766829220422260.xls
Temp file : C:\Users\MD1000\AppData\Local\Temp\c1234c137493179265536640669.xls
现在,我不想要额外的数字(长int)添加到文件名中。我怎样才能做到这一点?谢谢