Java Folder Read by Extension getFilesWithExtension(File aDirectory, final String aExtension)

Here you can find the source of getFilesWithExtension(File aDirectory, final String aExtension)

Description

Returns a list of files from a directory ending with a specific extension.

License

Open Source License

Parameter

Parameter Description
aDirectory The directory to search through.
aExtension The extention to search with.

Return

The array of files with a specific extension.

Declaration

public static File[] getFilesWithExtension(File aDirectory, final String aExtension) 

Method Source Code

//package com.java2s;
/*//from  w  w w .  ja  va 2 s  . c om
* Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
* All rights reserved.
* This component and the accompanying materials are made available
* under the terms of "Eclipse Public License v1.0"
* which accompanies this distribution, and is available
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
*
* Initial Contributors:
* Nokia Corporation - initial contribution.
*
* Contributors:
*
* Description: 
*
*/

import java.io.File;
import java.io.FileFilter;

public class Main {
    /**
     * Returns a list of files from a directory ending with a specific extension.
     * 
     * @param aDirectory The directory to search through.
     * @param aExtension The extention to search with.
     * @return The array of files with a specific extension.
     */
    public static File[] getFilesWithExtension(File aDirectory, final String aExtension) {
        return aDirectory.listFiles(new FileFilter() {
            public boolean accept(File lFile) {
                if (lFile.getName().endsWith(aExtension)) {
                    return true;
                }
                return false;
            }
        });
    }
}

Related

  1. getFiles(String path, String[] allowedExtension)
  2. getFiles2List(String path, String[] allowedExtension)
  3. getFilesFiteredByExtension(final File parent, final List extensions)
  4. getFilesForType(final File target, final String extension)
  5. getFilesFromExtension(String directory, String[] extensions)
  6. getFilesWithExtension(File dir, String extension)
  7. getFilesWithExtension(String directory, String extension)
  8. getFilesWithinPath(File path, String fileExtension)