Java File List Load getFileListing(File directory)

Here you can find the source of getFileListing(File directory)

Description

get File Listing

License

Apache License

Parameter

Parameter Description
directory a parameter

Return

@throws FileNotFoundException

Declaration

static public List getFileListing(File directory) throws FileNotFoundException 

Method Source Code

//package com.java2s;
/*//from w w  w  .  j a v a  2s.  c  o  m
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import java.io.File;
import java.io.FileNotFoundException;

import java.io.FilenameFilter;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;

public class Main {
    /**
     * @param directory
     * @return @throws
     *         FileNotFoundException
     */
    static public List getFileListing(File directory) throws FileNotFoundException {
        class JARFilter implements FilenameFilter {
            public boolean accept(File dir, String name) {
                return (name.endsWith(".jar"));
            }
        }

        List result = new ArrayList();
        File[] filesAndDirs = directory.listFiles();
        List filesDirs = Arrays.asList(filesAndDirs);
        Iterator filesIter = filesDirs.iterator();
        File file = null;

        while (filesIter.hasNext()) {
            file = (File) filesIter.next();

            if (!file.isFile()) {
                List deeperList = getFileListing(file);
                result.addAll(deeperList);
            } else {
                result.add(file);
            }
        }

        return result;
    }
}

Related

  1. getFileListDeep(File path)
  2. getFileListInFolder(String path)
  3. getFileListInFolderForImages(String imageFolder)
  4. getFileListing(File aStartingDir)
  5. getFileListing(File dir)
  6. getFileListing(File file)
  7. getFileListing(File file, String... extension)
  8. getFileListingLogs(File aStartingDir)
  9. getFileListingNoSort(File aStartingDir, boolean recursive)