Here you can find the source of getAllFiles(File root, FileFilter fileFilter)
public static File[] getAllFiles(File root, FileFilter fileFilter)
//package com.java2s; /******************************************************************************* * Copyright (c) 2000, 2012 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Common Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/cpl-v10.html * /* w w w . j ava2 s. c o m*/ * Contributors: * IBM Corporation - initial API and implementation *******************************************************************************/ import java.io.File; import java.io.FileFilter; import java.util.ArrayList; public class Main { public static File[] getAllFiles(File root, FileFilter fileFilter) { ArrayList<File> files = new ArrayList<File>(); if (root.isDirectory()) { collectAllFiles(root, files, fileFilter); File[] result = new File[files.size()]; files.toArray(result); return result; } return null; } private static void collectAllFiles(File root, ArrayList<File> collector, FileFilter fileFilter) { File[] files = root.listFiles(fileFilter); for (int i = 0; i < files.length; i++) { final File currentFile = files[i]; if (currentFile.isDirectory()) { collectAllFiles(currentFile, collector, fileFilter); } else { collector.add(currentFile); } } } }