Java Utililty Methods File List Load

List of utility methods to do File List Load

Description

The list of methods to do File List Load are organized into topic(s).

Method

ListgetFileList(File sourceDirectory, final String extension)
get File List
File[] listOfFiles = sourceDirectory.listFiles(new FilenameFilter() {
    @Override
    public boolean accept(File directoryName, String filename) {
        return filename.endsWith(extension)
                && new File(directoryName + File.separator + filename).canRead();
});
return Arrays.asList(listOfFiles);
...
ListgetFileList(File[] fileArray)
Get a list of files from a file array, where the directory entries are recursively resolved by all profile files inside the directory.
List<File> files = new ArrayList<File>();
for (int i = 0; i < fileArray.length; i++) {
    File file = fileArray[i];
    files.addAll(getList(file));
return files;
voidgetFileList(final File dir, final String extension, final List list, final int maxDepth)
Searches a directory to the specified depth for library files.

This method is recursive so be careful with the maximum depth
if (dir == null) {
    throw new IllegalArgumentException("Directory must not be null");
final File[] files = dir.listFiles();
if (files == null) {
    return;
for (final File file : files) {
...
voidgetFileList(final List fileList, final File root, final File[] ignoreList)
get File List
final File[] list = root.listFiles();
if (list == null) {
    return;
for (final File f : list) {
    if (f.isDirectory() && !isIgnored(ignoreList, f)) {
        getFileList(fileList, f, ignoreList);
    } else {
...
String[]getFileList(final String location)
get File List
File file = new File(location);
if (file.isDirectory()) {
    return file.list();
return null;
ListgetFileList(Map>> map, File dir, T key)
get File List
Map<T, List<String>> dirMap = map.get(dir);
if (dirMap == null)
    map.put(dir, dirMap = new HashMap<T, List<String>>());
List<String> files = dirMap.get(key);
if (files == null)
    dirMap.put(key, files = new ArrayList<String>());
return files;
ListgetFileList(String dir)
Get a file list under a directory
List<String> fileList = new ArrayList<String>();
File _dir = new File(dir);
File[] files = _dir.listFiles();
if (files != null) {
    for (int i = 0; i < files.length; i++) {
        if (files[i].isFile()) {
            String fileName = files[i].getAbsolutePath();
            fileList.add(fileName);
...
String[]getFileList(String dir)
get File List
try {
    File parent = new File(dir);
    if (!parent.isAbsolute() || !parent.isDirectory()) {
        return null;
    return parent.list();
} catch (Exception e) {
    return null;
...
File[]getFileList(String dir, final String extension)
get File List
File folder = new File(dir);
fileList = new ArrayList<File>();
traverse(folder, extension);
File[] fileArray = new File[fileList.size()];
fileList.toArray(fileArray);
return fileArray;
ListgetFileList(String dir, final String suffix)
get File List
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(".");
...