Here you can find the source of getFiles(File dir)
public static File[] getFiles(File dir)
//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; } }