Java Utililty Methods Folder Read

List of utility methods to do Folder Read

Description

The list of methods to do Folder Read are organized into topic(s).

Method

ListgetFilesAndFilesSubDirectories(String directoryName, String regexPattern)
get Files And Files Sub Directories
File directory = new File(directoryName);
File[] fList = directory.listFiles();
List<File> fileList = new ArrayList<File>();
if (fList == null) {
    return fileList;
for (File file : fList) {
    if (!file.getName().matches(regexPattern)) {
...
File[]getFilesArray(File baseStorePath, final String fileNameSearchPattern)
Below method will be used to get the file list
File[] listFiles = baseStorePath.listFiles(new FileFilter() {
    @Override
    public boolean accept(File pathname) {
        if (pathname.getName().indexOf(fileNameSearchPattern) > -1) {
            return true;
        return false;
});
return listFiles;
ArrayListgetFilesAsArrayList(String path)
get Files As Array List
ArrayList<String> mFileList = new ArrayList<String>();
File root = new File(path);
if (!storageReady()) {
    return null;
if (!root.exists()) {
    if (!createFolder(path)) {
        return null;
...
File[]getFilesByDate(String directory, final boolean earliestFirst)
get Files By Date
File[] files = new File(directory).listFiles();
Arrays.sort(files, new Comparator<File>() {
    @Override
    public int compare(File o1, File o2) {
        if (earliestFirst) {
            return new Long(o1.lastModified()).compareTo(new Long(o2.lastModified()));
        } else {
            return new Long(o2.lastModified()).compareTo(new Long(o1.lastModified()));
...
CollectiongetFilesByName(File path, String name)
Get all files existing in the path with the specified name.
final Collection<File> filesList = new ArrayList<>(1);
getFilesByNameRecursive(filesList, path, name);
return filesList;
ListgetFilesByPath(String toDir)
get all file in a folder
List fileList = new ArrayList();
File dir = new File(toDir);
File[] files = dir.listFiles();
String podOrderDir = toDir;
System.out.println(podOrderDir);
System.out.println("size:" + files.length);
for (int i = 0; i < files.length; i++) {
    if (files[i].isDirectory()) {
...
File[]getFilesByRegxFileName(String dir, final String regxName)
get Files By Regx File Name
if (dir == null)
    throw new NullPointerException("dir must not be null");
File dirc = new File(dir);
if (!dirc.exists() || !dirc.isDirectory()) {
    throw new IllegalArgumentException("dir must be exists directory");
File[] files = dirc.listFiles(new FileFilter() {
    @Override
...
ListgetFilesByType(String fileType, String path)
get Files By Type
return getFilesByType(fileType, allFiles(path));
File[]getFilesByType(String path, final String type)
get Files By Type
File dir = new File(path);
File[] files = dir.listFiles(new FileFilter() {
    public boolean accept(File afile) {
        return afile.getName().endsWith(type) && afile.isFile();
});
return files == null ? new File[] {} : files;
ListgetFilesCannotAccess(File... files)
Given a list of files, returns all the files which exist and that the process can't write to.
ArrayList<File> failAccess = new ArrayList<File>();
for (File file : files) {
    if (file.exists() && !file.canWrite()) {
        failAccess.add(file);
return failAccess;