多扩展名文件过滤器FilenameFilter

public class OnlyExtendName implements FilenameFilter {

	/**
	 * 扩展名数组
	 */
	private String[] extendName;

	/**
	 * 构造器
	 * @param extendName 所包含的扩展名,多个时用逗号分隔
	 */
	public OnlyExtendName(String extendName) {
		this.extendName = extendName.split(",");

	}

	public boolean accept(File dir, String name) {
		if (extendName != null) {
			boolean isAccept = false;
			for ( int i=0; i<extendName.length; i++ ){
				isAccept = isAccept || name.endsWith("."+extendName[i]);
			}
			return isAccept;
		}
		return false;
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {

	}

}

你可能感兴趣的:(JavaSE)