Java Folder Read getFiles(String path)

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

Description

Returns a single file object if the argument is a path to a specific file, or a list of directory files, if the argument is a path to a folder.

License

Open Source License

Declaration

public static final List<File> 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.List;

public class Main {
    /**//ww w  . j  a v  a2  s  .com
     * Returns a single file object if the argument is a path to a specific file,
     * or a list of directory files, if the argument is a path to a folder.
     */
    public static final List<File> getFiles(String path) {
        File file = new File(path);
        List<File> list = new ArrayList<File>();
        if (file.exists()) {
            if (file.isFile()) {
                list.add(file);
            } else if (file.isDirectory()) {
                File[] files = file.listFiles();
                if (files != null) {
                    for (int i = 0; i < files.length; i++) {
                        File f = files[i];
                        if (f.isFile()) {
                            list.add(f);
                        }
                    }
                }
            }
        }
        return list;
    }
}

Related

  1. getFiles(String folderName, String prefix)
  2. getFiles(String parent)
  3. getFiles(String path)
  4. getFiles(String path)
  5. getFiles(String path)
  6. getFiles(String PATH)
  7. getFiles(String path)
  8. getFiles(String path)
  9. getFiles(String path)