Java File Name Get getFileNameFilter(final String endsWith)

Here you can find the source of getFileNameFilter(final String endsWith)

Description

Erstellt einen Dateienamenfilter fuer Dateiendungen

License

Apache License

Parameter

Parameter Description
endsWith z.B. ".xml"

Return

FilenameFilter

Declaration

public static FilenameFilter getFileNameFilter(final String endsWith) 

Method Source Code


//package com.java2s;
/*// www . ja v a 2  s. c  o m
 * Copyright 2012 trewys GmbH
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * 
 */

import java.io.File;
import java.io.FilenameFilter;

public class Main {
    /**
     * Erstellt einen Dateienamenfilter fuer Dateiendungen
     * 
     * @param endsWith
     *            z.B. ".xml"
     * @return FilenameFilter
     */
    public static FilenameFilter getFileNameFilter(final String endsWith) {
        return new FilenameFilter() {
            public boolean accept(File directory, String fileName) {
                if (endsWith == null)
                    return true;
                return fileName.toLowerCase().endsWith(endsWith.toLowerCase());
            }
        };
    }
}

Related

  1. getFileName(String s)
  2. getFileName(String template, String className, String packageName)
  3. getFileName(String url, String basePath)
  4. getFileNameAndExt(String s)
  5. getFileNameArrayFromDirectory(String directoryLocation)
  6. getFilenameFilter(final String extension)
  7. getFilenameFilter(final String pFilter, final boolean pExclude)
  8. getFilenameForClassName(String className)
  9. getFileNameFromCanonical(String file)