Here you can find the source of getAllFiles(File dir, List
public static void getAllFiles(File dir, List<File> fileList) throws IOException
//package com.java2s; /******************************************************************************* * Copyright (c) [2012] - [2016] Codenvy, S.A. * 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:// ww w .j av a2 s . c o m * Codenvy, S.A. - initial API and implementation *******************************************************************************/ import java.io.File; import java.io.IOException; import java.util.List; public class Main { public static void getAllFiles(File dir, List<File> fileList) throws IOException { File[] files = dir.listFiles(); for (File file : files) { fileList.add(file); if (file.isDirectory()) { getAllFiles(file, fileList); } } } }