使用deleteOnExit()方法删除临时文件
import java.io.File; import java.nio.file.FileSystems; import java.nio.file.Files;// from N o w J a v a . c o m import java.nio.file.Path; public class Main { public static void main(String[] args) throws Exception { Path basedir = FileSystems.getDefault().getPath("C:/folder1/tmp"); String tmp_file_prefix = "test_"; String tmp_file_sufix = ".txt"; final Path tmp_file = Files.createTempFile(basedir, tmp_file_prefix, tmp_file_sufix); /*