Java Utililty Methods Folder Read

List of utility methods to do Folder Read

Description

The list of methods to do Folder Read are organized into topic(s).

Method

File[]getFiles(File... repertoires)
Return all the files (not directories) in the directories "repertoires" recursively.
File[] ret = null;
ArrayList<File> files = new ArrayList<File>();
for (int i = 0; i < repertoires.length; i++)
    addDirectoryContents(files, repertoires[i]);
ret = new File[files.size()];
for (int i = 0; i < files.size(); i++)
    ret[i] = files.get(i);
return ret;
...
ListgetFiles(final File dir)
get Files
final List<File> result = new ArrayList<File>();
final File[] filesAndDirs = dir.listFiles();
if (filesAndDirs == null) {
    System.out.println(dir);
final List<File> filesDirs = Arrays.asList(filesAndDirs);
for (File file : filesDirs) {
    result.add(file);
...
CollectiongetFiles(final File root, final String[] endings)
get Files
final ArrayList<File> rtr = new ArrayList<File>();
if (root.isFile()) {
    for (final String s : endings) {
        if (root.getAbsolutePath().endsWith(s)) {
            rtr.add(root);
            break;
    return rtr;
final File[] list = root.listFiles();
if (list == null) {
    return rtr;
for (final File f : list) {
    if (f.isDirectory()) {
        rtr.addAll(getFiles(f, endings));
    } else {
        if (endings == null || endings.length == 0) {
            rtr.add(f);
        } else {
            for (final String s : endings) {
                if (f.getAbsolutePath().endsWith(s)) {
                    rtr.add(f);
                    break;
return rtr;
ListgetFiles(final String classPath)
get Files
return Stream.of(classPath.split(File.pathSeparator)).map(File::new).collect(Collectors.toList());
voidgetFiles(final String path, Vector files)
get all files under the directory path
getFiles(new File(path), files);
ListgetFiles(List filepaths)
get Files
final List<File> files = new ArrayList<>();
for (Iterator<String> iterator = filepaths.iterator(); iterator.hasNext();) {
    files.add(new File(iterator.next()));
return files;
ListgetFiles(List filePaths)
get Files
List<File> files = new ArrayList<File>(filePaths.size());
for (String path : filePaths) {
    File file = new File(path);
    files.add(file);
return files;
ListgetFiles(List l, String directory)
get Files
if (l == null) {
    l = new ArrayList<String>();
File file = new File(directory);
if (file.isDirectory()) {
    String[] children = file.list();
    for (int i = 0; i < children.length; i++) {
        getFiles(l, new File(file, children[i]).getAbsolutePath());
...
CollectiongetFiles(String _path)
get Files
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;
ListgetFiles(String dir)
get Files
List<String> lstFiles = new ArrayList<>();
File file = new File(dir);
File[] files = file.listFiles();
if (files != null) {
    for (File f : files) {
        if (f.isDirectory()) {
            lstFiles.add(f.getAbsolutePath());
            lstFiles.addAll(getFiles(f.getAbsolutePath()));
...