Here you can find the source of getAllFiles(File inFileOrDir, boolean recurseDir)
public static List<File> getAllFiles(File inFileOrDir, boolean recurseDir)
//package com.java2s; /****************************************************************************** * Copyright (c) 2015 IBM Corporation.//from w ww. ja va2 s . c om * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: * IBM Corporation - initial API and implementation *****************************************************************************/ import java.io.File; import java.util.LinkedList; import java.util.List; import java.util.Stack; public class Main { public static List<File> getAllFiles(File inFileOrDir, boolean recurseDir) { final List<File> ret = new LinkedList<File>(); Stack<File> stack = new Stack<File>(); stack.add(inFileOrDir); while (!stack.isEmpty()) { File f = stack.pop(); if (f.isFile()) { ret.add(f); } else { assert f.isDirectory() : f; if (recurseDir) { for (File cf : f.listFiles()) { stack.add(cf); } } } } return ret; } }