使用createTempFile()方法创建临时文件
import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; /* n o w j a v a . c o m - 时 代 Java 提 供 */ public class Main { public static void main(String[] args) { String tmp_file_prefix = "test_"; String tmp_file_sufix = ".txt"; try { // passing null prefix/suffix Path tmp_1 = Files.createTempFile(null, null); System.out.println("TMP: " + tmp_1.toString()); // set a prefix and a suffix Path tmp_2 = Files.createTempFile(tmp_file_prefix, tmp_file_sufix); System.out.println(