In general, when we save a file in a project, we store the directory information in a single table and store the file information in another table.
When we need to delete the specified directory, we first need to delete all the information in the database directory and subdirectories, then delete the file information, and finally delete the created file directory, if there are subdirectories, you need to use recursive Delete, that is:
Process of deleting subdirectories and files in the specified directory in the business logic layer
Delete directory information from the database Cataloguedao.deletecat (dir);//delete the file information in the database Filedao.deletefile (dir);// Use recursive delete function Deletedir recursively delete the specified directory Deletedir (path + dir.getname ());
Deletedir the implementation of the function, recursively deletes the file under the specified directory:
public static void Deletedir (String path) {File File = new file (path); if (File.exists ()) {if (File.isdirectory ()) {file[] fi Les = File.listfiles (); for (file subfile:files) {if (Subfile.isdirectory ()) Deletedir (Subfile.getpath ()); Elsesubfile.delete ();}} File.delete ();}}
How Java recursively deletes subdirectories and files in a directory