Java Folder Read getFiles(String dir)

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

Description

Returns the files in the given directory (only normal files, no subdirectories).

License

BSD License

Parameter

Parameter Description
dir a directory

Return

files in the directory

Declaration

public static File[] getFiles(String dir) 

Method Source Code

//package com.java2s;
//License from project: BSD License 

import java.io.File;

import java.util.ArrayList;

public class Main {
    /**// w  w  w.ja  v  a2s  .c o  m
     * Returns the files in the given directory (only normal files, no
     * subdirectories).
     * 
     * @param dir a directory
     * @return files in the directory
     */
    public static File[] getFiles(String dir) {
        ArrayList<File> files = new ArrayList<File>();

        // only return normal files, no subdirectories
        File[] filesOrDirs = new File(dir).listFiles();
        for (File fileOrDir : filesOrDirs)
            if (fileOrDir.isFile())
                files.add(fileOrDir);

        return files.toArray(new File[files.size()]);
    }
}

Related

  1. getFiles(List filePaths)
  2. getFiles(List l, String directory)
  3. getFiles(String _path)
  4. getFiles(String dir)
  5. getFiles(String dir)
  6. getFiles(String directoryPath)
  7. getFiles(String dirName, int number)
  8. getFiles(String folderName, String prefix)
  9. getFiles(String parent)