Java tutorial
//package com.java2s; import java.io.File; import java.io.FileFilter; import java.util.Arrays; import java.util.Enumeration; import java.util.Vector; public class Main { public static Enumeration getAllFilesIn(File dir) { File[] files; if (dir.isDirectory()) { files = dir.listFiles(new FileFilter() { public boolean accept(File f) { if (f.isDirectory()) return false; return (f.getName().endsWith(".txt")); } }); Arrays.sort(files); } else { files = new File[] { dir }; } Vector vect = new Vector(files.length); for (int i = 0; i < files.length; ++i) vect.addElement(files[i]); return vect.elements(); } }