Java – find specific file types from folders and their subfolders
•
Java
I'm writing a method to get specific file types from folders and subfolders, such as PDF or txt, but I can't solve this problem This is my code
// .............list file
File directory = new File(directoryName);
// get all the files from a directory
File[] fList = directory.listFiles();
for (File file : fList) {
if (file.isFile()) {
System.out.println(file.getAbsolutePath());
} else if (file.isDirectory()) {
listf(file.getAbsolutePath());
}
}
My current method lists all files, but I need specific files
Solution
if(file.getName().endsWith(".pdf")) {
if(file.getName().endsWith(".pdf")) {
//it is a .pdf file!
}
/ *** /
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码
