1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
/* Delete file or directory when virtual machine terminates This Java example shows how to delete a particular file or directory from filesystem when Java Virtual Machine terminates using deleteOnExit method of Java File class. */ import java.io.*; public class DeleteFileWhenVMTerminates { public static void main(String[] args) { //create File object File file = new File("C://FileIO//DeleteDemo.txt"); /* * To delete a particular file or directory when Java VM exits, use * void deleteOnExit() method. * * This method request to delete a specified file or directory to be deleted * when virtual machine terminates normally. * */ file.deleteOnExit(); /* * Please note that, once deletion has been requested, it is not possible to * cancel that operation. */ } } |
Add Comment