void deleteOnExit boolean delete boolean equals(Object obj) 描述 所述java.io.File.deleteOnExit()方法删除当虚拟机终止由抽象路径名定义的文件或目录。文件或目录在注册时以相反的顺序删除。 声明 以下是java.io.File.deleteOnExit()方法的声明 public void deleteOnExit() 参数 NA 返回值 该方法不返回任何值。 异常 SecurityException - 如果SecurityManager.checkWrite(java.lang.String)方法拒绝对文件的删除访问 实例 以下示例显示了java.io.File.deleteOnExit()方法的用法。 package com.tutorialspoint; import java.io.File; public class FileDemo { public static void main(String[] args) { File f = null; try { // creates temporary file f = File.createTempFile("tmp", ".txt"); // prints absolute path System.out.println("File path: "+f.getAbsolutePath()); // deletes file when the virtual machine terminate f.deleteOnExit(); // creates temporary file f = File.createTempFile("tmp", null); // prints absolute path System.out.print("File path: "+f.getAbsolutePath()); // deletes file when the virtual machine terminate f.deleteOnExit(); } catch(Exception e) { // if any error occurs e.printStackTrace(); } } } 让我们编译并运行上面的程序,这将产生以下结果 File path: C:\Users\BABAI\AppData\Local\Temp\tmp1307307616656986083.txt File path: C:\Users\BABAI\AppData\Local\Temp\tmp4586112702019401940.tmp boolean delete boolean equals(Object obj)