Here you can find the source of getFileListByDFS(File file)
public static List<File> getFileListByDFS(File file) throws IOException
//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; } }