Java File List Load getFileList(File folder, String type)

Here you can find the source of getFileList(File folder, String type)

Description

get File List

License

Open Source License

Parameter

Parameter Description
folder the folder you want to check
type the file type you want to filter

Declaration

public static List<File> getFileList(File folder, String type) 

Method Source Code


//package com.java2s;

import java.io.File;

import java.util.ArrayList;

import java.util.List;

public class Main {
    public static final String FILE_TYPE_FOLDER = "dir";

    /**/*from   w w  w  .  j a  v a2  s .  co  m*/
     * 
     * @param folder
     *            the folder you want to check
     * @param type
     *            the file type you want to filter
     * @return
     */
    public static List<File> getFileList(File folder, String type) {
        List<File> fileNameList = new ArrayList<File>();
        File[] files = folder.listFiles();
        for (File file : files) {
            if (getFileType(file).equalsIgnoreCase(type)) {
                fileNameList.add(file);
            }
        }
        return fileNameList;
    }

    /**
     * 
     * @param file
     * @return the file type like "exe"
     */
    public static String getFileType(File file) {
        if (file.isDirectory()) {
            return FILE_TYPE_FOLDER;
        } else {
            String[] strArray = file.getName().split("\\.");

            int length = strArray.length;
            if (length > 1) {
                return strArray[length - 1];

            } else {
                return "unknown";
            }
        }
    }
}

Related

  1. getFileList(File f)
  2. getFileList(File f, FileFilter filter, boolean recursive, boolean wantDirectory, boolean wantHidden, ArrayList list)
  3. getFileList(File file)
  4. getFileList(File file)
  5. getFileList(File file, String[] suffixs)
  6. getFileList(File sourceDirectory, final String extension)
  7. getFileList(File[] fileArray)
  8. getFileList(final File dir, final String extension, final List list, final int maxDepth)
  9. getFileList(final List fileList, final File root, final File[] ignoreList)