Java tutorial
//package com.java2s; //License from project: Open Source License import android.annotation.SuppressLint; import java.io.File; public class Main { /** Filter which accepts every file */ public static final String FILTER_ALLOW_ALL = "*.*"; /** * This method checks that the file is accepted by the filter * * @param file * - file that will be checked if there is a specific type * @param filter * - criterion - the file type(for example ".jpg") * @return true - if file meets the criterion - false otherwise. */ @SuppressLint("DefaultLocale") public static boolean accept(final File file, final String filter) { if (filter.compareTo(FILTER_ALLOW_ALL) == 0) { return true; } if (file.isDirectory()) { return true; } int lastIndexOfPoint = file.getName().lastIndexOf('.'); if (lastIndexOfPoint == -1) { return false; } String fileType = file.getName().substring(lastIndexOfPoint).toLowerCase(); return fileType.compareTo(filter) == 0; } }