您好,我正在尝试从源文件夹(如下)中检索 .mp3
类型的所有文件的名称
下面是我用来区分文件类型并添加到列表的代码。但是我不知道应该在 directory
中输入哪个参数,它应该是 music
文件夹,但我不知道如何表示这一点。
File dir = new File("");
String[] files = dir.list(new FilenameFilter() {
public boolean accept(File dir, String name) {
return name.toLowerCase().endsWith(".mp3");
};
});
for(int a = 0; a < files.length; a++)
{
musicList.add(files[a]);
}
最佳答案
试试这个。
List<String> result = Files.find(Paths.get("music"), 100,
(p, a) -> p.toString().toLowerCase().endsWith(".mp3"))
.map(path -> path.toString())
.collect(Collectors.toList());
关于java - 查找项目源文件夹中特定扩展名的所有文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40041109/