Here you can find the source of getAllFilesInDirectory(File directory, List
public static void getAllFilesInDirectory(File directory, List<File> files)
//package com.java2s; /******************************************************************************* * Copyright (c) 2016 Weasis Team and others. * 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://from ww w . ja v a 2 s . c om * Nicolas Roduit - initial API and implementation *******************************************************************************/ import java.io.File; import java.util.List; public class Main { public static void getAllFilesInDirectory(File directory, List<File> files) { File[] fList = directory.listFiles(); for (File f : fList) { if (f.isFile()) { files.add(f); } else if (f.isDirectory()) { getAllFilesInDirectory(f, files); } } } }