我正在编写一种从文件夹和子文件夹中获取特定文件类型(例如pdf或txt)的方法,但是我却无法解决此问题。这是我的代码
// .............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());
}
}
我当前的方法列出了所有文件,但我需要特定的文件
if(file.getName().endsWith(".pdf")) {
//it is a .pdf file!
}
/ * ** /
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句