brian brian - 1 year ago 119
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");
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download