I want to be able to count all the save games a user has created.
Using Java, how can I count all the files in a directory with a specific extension?
This code counts all the files regardless of extension:
public class MCVE {
public static void main(String[] args) {
countFiles();
}
private static void countFiles() {
long amountOfFiles = 0;
try {
Stream<Path> files = Files.list(Paths.get("./saves"));
amountOfFiles = files.count();
System.out.println(amountOfFiles);
} catch (IOException e) {
e.printStackTrace();
}
}
}