集册 Java实例教程 删除目录

删除目录

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

481
删除目录
/* 来 自 nowjava*/


//package com.nowjava;

import java.io.File;


public class Main {


    public static boolean deleteDirectory(File path) {

        if (path.exists()) {

            File[] files = path.listFiles();

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

                if (files[i].isDirectory()) {

                    deleteDirectory(files[i]);

                } else {/**from 时   代    Java - nowjava.com**/

                    files[i].delete();

                }

            }

        }

        return (path.delete());

    }

}