Java JFileChooser Filter fileEndsInValidExtension(File file, FileNameExtensionFilter filter)

Here you can find the source of fileEndsInValidExtension(File file, FileNameExtensionFilter filter)

Description

file Ends In Valid Extension

License

Open Source License

Declaration

public static boolean fileEndsInValidExtension(File file, FileNameExtensionFilter filter) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.io.File;

import javax.swing.filechooser.FileNameExtensionFilter;

public class Main {
    public static final String WILDCARD = "*";
    public static final String FILE_NAME_WITH_EXTENSION_REGEX = "^.*\\..+$";

    public static boolean fileEndsInValidExtension(File file, FileNameExtensionFilter filter) {
        for (String ext : filter.getExtensions()) {
            if (file.toString().endsWith("." + ext)
                    || (ext.equals(WILDCARD) && file.toString().matches(FILE_NAME_WITH_EXTENSION_REGEX))) {
                return true;
            }/*from   w  w w .j  av a 2s  .  co  m*/
        }
        return false;
    }
}

Related

  1. createFileFilter(final String description, String extension)
  2. createFileFilter(final String ext, final String desc)
  3. createFileFilter(final String filter)
  4. createFileFilter(final String filterName, final String... extensionPatterns)
  5. createFileFilter(String text, String[]... suffixes)
  6. fileNameAutoExtend(FileFilter filter, File file)
  7. getBinaryFileFilter()
  8. getCustomFileFilter(String desc, String[] validExtensions)
  9. getFileChooserFilter(java.util.List allowedExtensions)