Java Folder Read getFiles(File dir)

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

Description

get Files

License

Open Source License

Declaration

public static File[] getFiles(File dir) 

Method Source Code


//package com.java2s;
/*//w w w . j  av  a2 s.  c om
 * This program is free software: you can redistribute it and/or modify it 
 * under the terms of the GNU General Public License as published by 
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 */

import java.io.*;
import java.util.Vector;

public class Main {
    public static File[] getFiles(File dir) {
        if (!dir.isDirectory()) {
            throw new IllegalArgumentException();
        }

        Vector files = new Vector();
        String[] list = dir.list();
        if ((list != null) && (list.length != 0)) {
            int len = list.length;
            for (int i = 0; i < len; i++) {
                File current = new File(dir, list[i]);
                if (current.canRead() && current.isFile()) {
                    files.addElement(current);
                }
            }

            int size = files.size();
            File[] ret = new File[size];
            for (int i = 0; i < size; i++) {
                ret[i] = (File) files.elementAt(i);
            }

            return ret;
        }

        return null;
    }
}

Related

  1. getFiles(Collection folders)
  2. getFiles(File apkFile, Pattern regex)
  3. getFiles(File archive)
  4. getFiles(File dir)
  5. getFiles(File dir)
  6. getFiles(File dir, File... excludes)
  7. getFiles(File dir, final String pattern)