集册 Java实例教程 删除目录

删除目录

欢马劈雪     最近更新时间:2020-01-02 10:19:05

438
删除目录


import java.io.File;/*时代Java公众号 提 供*/


public class Main {

  public static void main(String[] argv) {

    // Delete an empty directory

    boolean success = (new File("directoryName")).delete();

    if (!success) {

      // Deletion failed

    }

  }

  public static boolean deleteDir(File dir) {

    if (dir.isDirectory()) {

      String[] children = dir.list();

      for (int i = 0; i < children.length; i++) {

        boolean success = deleteDir(new File(dir, children[i]));

        if (!success) {

          
展开阅读全文