The Java standard library provides a way to get an array of elements Filethat are in a directory through File # listFiles . Primarily:
File theDirectory = new File("/home/example");
File[] children = theDirectory.listFiles();
In addition, there is an overloaded method that allows you to specify a filter that you can use to trim items returned in the list.
File theDirectory = new File("/home/example");
File[] children = theDirectory.listFiles(new FileFilter(){
public boolean accept(File file) {
if (file.isFile()) {
return true;
}
return false;
}
});
, String, Pattern Matcher. , , , File.listFiles(FilenameFilter), , .