brian brian - 1 year ago 87
Java Question

How to delete all files and folders in one folder on Android

I use this code to delete all files:

File root = new File("root path");
File[] Files = root.listFiles();
if(Files != null) {
int j;
for(j = 0; j < Files.length; j++) {

It will delete false where
is a folder.

I want to delete folder and all its sub files.

How can I modify this?

Answer Source

Simplest way would be to use FileUtils.deleteDirectory from the Apache Commons IO library.

File dir = new File("root path");