1 ImportJava.io.File;2 Importjava.text.ParseException;3 ImportJava.text.SimpleDateFormat;4 Importjava.util.Date;5 ImportJava.util.Timer;6 ImportJava.util.TimerTask;7 8 /*9 *: Delete the specified directory at the specified timeTen * Set As a timed task One */ A Public classTimertest { - Public Static voidMain (string[] args)throwsException { -Timer T =NewTimer (); the -String s = "2016-04-09 20:46:59"; -SimpleDateFormat SDF =NewSimpleDateFormat ("Yyyy-mm-dd HH:mm:ss"); -Date d =Sdf.parse (s); + -T.schedule (NewDeleteFolder (), d); + } A } at - classDeleteFolderextendsTimerTask { - @Override - Public voidrun () { -File Srcfolder =NewFile ("Demo"); - DeleteFolder (srcfolder); in } - to Private voidDeleteFolder (File srcfolder) { +file[] Filearr =srcfolder.listfiles (); - if(Filearr! =NULL) { the for(File file:filearr) { * if(File.isdirectory ()) { $ deletefolder (file);Panax Notoginseng}Else { - File.delete (); the } + } A } the //This statement is used to delete a folder directly when the folder is already empty. 43 Srcfolder.delete (); - } $}
Delete the contents of the specified folder folder under Java and delete the use recursion scheme