Java File List Load getFileListByDFS(File file)

Here you can find the source of getFileListByDFS(File file)

Description

get File List By DFS

License

Apache License

Declaration

public static List<File> getFileListByDFS(File file) throws IOException 

Method Source Code

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

import java.io.File;

import java.io.IOException;

import java.util.ArrayList;

import java.util.List;

import java.util.Stack;

public class Main {

    public static List<File> getFileListByDFS(File file) throws IOException {
        Stack<File> stack = new Stack<File>();
        stack.push(file);//from w w w . jav  a  2s.co m
        File fileInStack = null;
        List<File> fileList = new ArrayList<File>();
        while (!stack.isEmpty()) {
            fileInStack = stack.pop();
            File[] files = fileInStack.listFiles();
            for (File eachFile : files) {
                if (eachFile.isFile()) {
                    fileList.add(eachFile);
                } else {
                    stack.push(eachFile);
                }
            }
        }
        return fileList;
    }
}

Related

  1. getFileList(String path, String filterName)
  2. getFileList(String path, String regex)
  3. getFileList(String path, String searchString)
  4. getFileList(String s)
  5. getFileList(String zipFilePath)
  6. getFileListByExtension(final String location, final String extension)
  7. getFileListByRegex(String dir, final String regex)
  8. getFileListDeep(File path)
  9. getFileListInFolder(String path)