我是靠谱客的博主 激昂帽子,这篇文章主要介绍如何在Java中检查目录是否为空,现在分享给大家,希望可以做个参考。

这是检查目录是否为空的示例。

package com.mkyong.file;

import java.io.File;

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

	File file = new File("C:\folder");
		
	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");
			
	}
    }
}

翻译自: https://mkyong.com/java/how-to-check-if-directory-is-empty-in-java/

最后

以上就是激昂帽子最近收集整理的关于如何在Java中检查目录是否为空的全部内容,更多相关如何在Java中检查目录是否为空内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(56)

评论列表共有 0 条评论

立即
投稿
返回
顶部