Here you can find the source of getFiles(File dir)
Parameter | Description |
---|---|
dir | the directory to traverse for files |
public static File[] getFiles(File dir)
//package com.java2s; // Licensed under the Apache License, Version 2.0 (the "License"); import java.io.File; import java.util.LinkedList; import java.util.List; public class Main { /**/* w ww .j ava2 s. co m*/ * Recursively gets all the files in a directory * * @param dir the directory to traverse for files */ public static File[] getFiles(File dir) { List<File> list = new LinkedList<File>(); getAllFilesRecursively(dir, list); File[] arr = new File[list.size()]; list.toArray(arr); return arr; } private static void getAllFilesRecursively(File dir, List<File> filelist) { File[] files = dir.listFiles(); if (files == null) { return; } int i; for (i = 0; i < files.length; ++i) { if (files[i].isFile()) { filelist.add(files[i]); } else if (files[i].isDirectory()) { getAllFilesRecursively(files[i], filelist); } } } }