Java-检查文件夹是否是空文件夹

Java-检查文件夹是否是空文件夹

Tags: Java

摘要

Java-检查文件夹是否是空文件夹

检查文件夹是否是空文件夹

package cn.javacore.io.directory;

import java.io.File;

public class _05_CheckEmptyDirectoryExample {
    public static void main(String[] args) {

        File file = new File("/home/zhu/javacore.cn");

        if (file.isDirectory()) {

            if (file.list().length > 0) {

                System.out.println("Directory is not empty!");

            } else {

                System.out.println("Directory is empty!");

            }

        } else {

            System.out.println("This is not a directory");

        }
    }
}