Java判断文件夹下是否有指定后缀名的文件(txt,jpg,pdf等)

    public static boolean WhetherExistTXTFile(){
		String path = "D:\\UAT\\Node0\\Attrquery";
		File file = new File(path);
		File filelist[] = file.listFiles();
		for(File f : filelist){
			String filename = f.getName();
			if(filename.endsWith("txt")){
				logger.info("Existence of txt file : " + f.getAbsolutePath());
				return true;
			}
		}
		return false;
    }

猜你喜欢

转载自blog.csdn.net/weixin_42126947/article/details/81132627