我有这个实现的类FilenameFilter
package Logic;
import java.io.File;
import java.io.FilenameFilter;
public class Filter implements FilenameFilter {
String name;
public Filter(String name) {
this.name = name;
}
@Override
public boolean accept(File dir, String filename) {
return name.contains("bluetooth");
}
}
我在这个方法中使用这个类:
public String searchForBluetoothFolder() {
String folderNameToSearchFor = "bluetooth";
File root = sdCard;
FilenameFilter filter = new Filter(folderNameToSearchFor);
String[] bluetoothFolder = root.list(filter);
for(int i = 0; i < bluetoothFolder.length; i++) {
Log.i("Bluetooth: ", bluetoothFolder[i]);
}
return "";
}
在 for 循环中,输出只是根目录中的所有文件,而不是那些以蓝牙为名称的文件。我在这里做错了什么?