You can use the FileFilter
interface for this:
File f = new File("/home/user/pasta");
File[] files = f.listFiles(new FileFilter() {
@Override
public boolean accept(File pathname) {
return pathname.isFile();
}
});
System.out.println(files.length);
The accept
method of inteface FileFilter
is called for each file in the folder in question. In the case on screen a test is done if the item is a file ( isFile()
), if it returns true and the file enters the vector that will be returned.
In Java 8 you could lay claim to Lambda:
File file = new File("/home/user/pasta");
Arrays.stream(file.listFiles())
.filter(f -> f.isFile())
.forEach(f -> System.out.println(f.getAbsolutePath()));
Where is running System.out.println(f.getAbsolutePath())
you could call the routine that does the parser of the file.
To tell the files do this:
long quantidade = Arrays.stream(file.listFiles())
.filter(f -> f.isFile())
.count();