import java.io.File;
public class DirIsNull {
public static void main(String[] args) {
File file = new File("/home/huanyu/Desktop");
String[] files = file.list();
/**
* 打印文件名称
*/
for (String f:files ) {
System.out.println(f+files.length);
}
/**
* 判断眼泪是否为空
*/
if (files.length>0){
System.out.println("目录不为空!");
}else {
System.out.println("目录为空!!");
}
}
}
![img_cb4c30a4fc8377bfce9ec34f13f25be3.png](https://yqfile.alicdn.com/img_cb4c30a4fc8377bfce9ec34f13f25be3.png?x-oss-process=image/resize,w_1400/format,webp)