Java File List Load getFileList(File dir, ArrayList list)

Here you can find the source of getFileList(File dir, ArrayList list)

Description

get File List

License

Open Source License

Declaration

private static void getFileList(File dir, ArrayList<File> list) 

Method Source Code


//package com.java2s;
/*/*from w  w w  .  j  a  va2  s.c  o  m*/
 * Unitex
 *
 * Copyright (C) 2001-2016 Universit? Paris-Est Marne-la-Vall?e <unitex@univ-mlv.fr>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA.
 *
 */

import java.io.File;

import java.util.ArrayList;
import java.util.Collections;

public class Main {
    /**
     * Returns a sorted list containing all files contained in
     * the given directory.
     */
    public static ArrayList<File> getFileList(File dir) {
        ArrayList<File> list = new ArrayList<File>();
        getFileList(dir, list);
        Collections.sort(list);
        return list;
    }

    private static void getFileList(File dir, ArrayList<File> list) {
        if (dir == null || !dir.exists())
            return;
        list.add(dir);
        if (dir.isFile()) {
            return;
        }
        File[] files = dir.listFiles();
        if (files == null)
            return;
        for (File f : files) {
            getFileList(f, list);
        }
    }
}

Related

  1. getFileList(File dir, Set arrayList)
  2. getFileList(File dir, String regex)
  3. getFileList(File dirFile, final String filenamePrefix)
  4. getFileList(File f)