Java File List Load getFileList(String dir)

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

Description

Get a file list under a directory

License

Apache License

Parameter

Parameter Description
dir a parameter

Declaration

public static List<String> getFileList(String dir) 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.io.*;

import java.util.ArrayList;
import java.util.List;

public class Main {
    /**//from w  ww. j  av a  2s .co m
     * Get a file list under a directory
     *
     * @param dir
     * @return
     */
    public static List<String> getFileList(String dir) {
        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);
                }
            }
        }
        return fileList;
    }

    /**
     * Check if it is a valid file
     *
     * @param file
     * @return
     */
    public static boolean isFile(String file) {
        File f = new File(file);
        return f.exists() && f.isFile();
    }
}

Related

  1. getFileList(File[] fileArray)
  2. getFileList(final File dir, final String extension, final List list, final int maxDepth)
  3. getFileList(final List fileList, final File root, final File[] ignoreList)
  4. getFileList(final String location)
  5. getFileList(Map>> map, File dir, T key)
  6. getFileList(String dir)
  7. getFileList(String dir, final String extension)
  8. getFileList(String dir, final String suffix)
  9. getFileList(String directory, String filterRegexp)