I have some sort of batch program that should pick up a file from a directory and process it.
Since this program is supposed to:
- run on JDK 5,
- be small (no external libraries)
- and fast! (with a bang)
…what is the best way to only pick one file from the directory – without using File.list() (might be hundreds of files)?
In Java 7 you could use a DirectoryStream, but in Java 5, the only ways to get directory entries are
list()andlistFiles().Note that listing a directory with hundreds of files is not ideal but still probably no big deal compared to processing one of the files. But it would probably start to be problematic once the directory contains many thousands of files.