欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

从键盘接收一个文件夹路径,删除该文件夹

程序员文章站 2022-05-15 09:59:11
...
public static void main(String[] args) {
        File file = new File("E:\\abc");
        if (!fun3(file)) {
            System.out.println("删除成功!");
        }
}
   /**
     * 3.从键盘接收一个文件夹路径,删除该文件夹。
     */
    public static boolean fun3(File file) {
        File[] list = file.listFiles();
        for (File f :
                list) {
            if (f.isDirectory()) {
                fun3(f);
            }
            f.delete();
        }
        file.delete();
        if (list == null) {
            return true;
        }
        return false;
    }