I want to count how many image are in a directory. I have a copy of some code from internet which can detect the total file inside a directory.
import java.io.*;
public class CountFilesInDirectory {
public static void main(String[] args) {
File f = new File("/home/pc3/Documents/ffmpeg_temp/");
int count = 0;
for (File file : f.listFiles()) {
if (file.isFile()) {
count++;
}
}
System.out.println("Number of files: " + count);
}
}
I wish to count a specific file type like jpg/txt. What should I do?