If you are using Java 7, Nio2's new Path get the files of a directory as a Stream (like an iterator)
try (DirectoryStream<Path> stream = Files.newDirectoryStream(dir)) {
for (Path file: stream) {
System.out.println(file.getFileName());
}
} catch (IOException | DirectoryIteratorException x) {
// IOException can never be thrown by the iteration.
// In this snippet, it can only be thrown by newDirectoryStream.
System.err.println(x);
}
Check out the tutorial : http://docs.oracle.com/javase/tutorial/essential/io/dirs.html#listdir