public void DeleteFile (String delpath) throws Exception {try {File file = new file (Delpath); Returns True if (!file.isdirectory ()) {File.delete () if and only if the file represented by this abstract pathname exists and is a directory; } else if (File.isdirectory ()) {string[] filelist = File.list (); for (int i = 0; i < filelist.length; i++) {File Delfile = new File (Delpath + "/" + filelist[i]); if (!delfile.isdirectory ()) {delfile.delete (); System.out. println (Delfile.getabsolutepath () + "Delete files successfully"); } else if (Delfile.isdirectory ()) {DeleteFile (Delpath + "/" + filelist[i]); }} System.out.println (File.getabsolutepath () + "Delete succeeded"); File.delete (); }} catch (FileNotFoundException e) {System.out.println ("DeleteFile () Exception:" + e.getmessage ()); } }
Java cascade Delete all files under folder