Java如何检查目录是否为空?

package org.nhooo.example.io;

import java.io.File;

public class EmptyDirCheck {
    public static void main(String[] args) {
        File file = new File("C:/Users/nhooo/Documents");

        // 检查对象是否代表目录。
        if (file.isDirectory()) {
            //获取目录中的文件列表。当其长度不为零时
            // 文件夹不为空。
            String[] files = file.list();

            if (files != null && files.length > 0) {
                System.out.println("The " + file.getPath() + " is not empty!");
            }
        }
    }
}