Java I/O How to - Delete folder








Question

We would like to know how to delete folder.

Answer

/*ww w.ja va2s.  c o  m*/
import java.io.File;

public class Main {
  public static void deleteFolder(File f) {
    File[] files = f.listFiles();
    for (File fi : files) {
      if (fi.isDirectory()) {
        deleteFolder(fi);
      }
      fi.delete();
    }
  }
}