Answer the question
In order to leave comments, you need to log in
How to delete all folders (with files laid out in them) and files from a folder?
The context is the following: there is one folder. It contains several files, as well as several folders in which, in turn, there are several files.
How can I completely empty this folder?
At the moment I tried to implement it through the following code:
recursiveDelete(new File("C:/ProgramData/Ex"));
public static void recursiveDelete(File file) throws NullPointerException {
if (!file.exists())
return;
if (file.isDirectory()) {
for (File f : file.listFiles()) {
recursiveDelete(f);
}
}
file.delete();
System.out.println("Удаленный файл или папка: " + file.getAbsolutePath());
}
Answer the question
In order to leave comments, you need to log in
fandorin_official is the job you want to do for you or do you need to delete the directory recursively?
Class org.apache.commons.io.FileUtils
https://commons.apache.org/proper/commons-io/javad...
static void deleteDirectory(File directory)
Deletes a directory recursively.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question