Java File List Load getFileList(String dir, final String suffix)

Here you can find the source of getFileList(String dir, final String suffix)

Description

get File List

License

Apache License

Declaration

public static List<String> getFileList(String dir, final String suffix) 

Method Source Code


//package com.java2s;
/*/*from w ww  .j a va2  s.c om*/
 * #%L
 * Util.java - method51 - University of Sussex - 2,013
 * %%
 * Copyright (C) 2013 - 2014 University of Sussex
 * %%
 * 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.
 * #L%
 */

import java.io.*;

import java.util.*;

public class Main {
    public static List<String> getFileList(String dir, final String suffix) {

        File f = new File(dir);

        if (!f.exists())
            return Collections.EMPTY_LIST;

        if (!f.isDirectory())
            return Arrays.asList(f.getName());

        List<String> names = new ArrayList<>(Arrays.asList(f.list(new FilenameFilter() {
            public boolean accept(File dir, String name) {
                return name.toLowerCase().endsWith(suffix) && !name.startsWith(".");
            }
        })));

        Collections.sort(names);

        return names;
    }
}

Related

  1. getFileList(final String location)
  2. getFileList(Map>> map, File dir, T key)
  3. getFileList(String dir)
  4. getFileList(String dir)
  5. getFileList(String dir, final String extension)
  6. getFileList(String directory, String filterRegexp)
  7. getFileList(String directoryPath)
  8. getFileList(String filePath, FileFilter fileFilter, boolean recursive)
  9. getFileList(String folderPath)