Java Folder Read getFiles(String _path)

Here you can find the source of getFiles(String _path)

Description

get Files

License

Open Source License

Declaration

public static Collection<String> getFiles(String _path) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.io.File;

import java.util.ArrayList;
import java.util.Collection;

public class Main {
    public static Collection<String> getFiles(String _path) {
        Collection<String> files = new ArrayList<String>();

        File[] listOfFiles = new File(_path).listFiles();

        if (listOfFiles != null)
            for (File f : listOfFiles)
                if (f.isFile())
                    files.add(f.getName());

        return files;
    }//from w  w  w.  j ava 2  s  . co m

    public static Collection<String> getFiles(String _path, String... _ext) {
        Collection<String> files = new ArrayList<String>();

        File[] listOfFiles = new File(_path).listFiles();

        if (listOfFiles != null)
            for (File f : listOfFiles)
                if (f.isFile()) {
                    String path = f.getAbsolutePath();
                    String ext = path.substring(path.lastIndexOf(".") + 1);
                    for (String extInc : _ext)
                        if (ext.equalsIgnoreCase(extInc))
                            files.add(f.getName());
                }

        return files;
    }
}

Related

  1. getFiles(final String classPath)
  2. getFiles(final String path, Vector files)
  3. getFiles(List filepaths)
  4. getFiles(List filePaths)
  5. getFiles(List l, String directory)
  6. getFiles(String dir)
  7. getFiles(String dir)
  8. getFiles(String dir)
  9. getFiles(String directoryPath)