JAVA IO - deleteOnExit

如果存在就删除文件, 否则什么都不做

Requests that the file or directory denoted by this abstract pathname be deleted when the virtual machine terminates. Files (or directories) are deleted in the reverse order that they are registered. 

import java.io.File;


public class FileDelete {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		File file = new File("c:\\work\\test");
//		if(!file.exists()){
//			System.out.println("No such file");
//		}else{
//			if(file.delete()){
//				System.out.println("Delete OK");
//			}else{
//				System.out.println("Delete wrong");
//			}
//		}
		
		file.deleteOnExit();
	}

}



你可能感兴趣的:(File,deleteOnExit)