所以我只想列出在指定目錄中的目錄。我嘗試了FileFilter和FilenameFilter。兩者都不適合我,因爲它們還包含文件。但不知何故,其他人對此沒有任何問題。Java FileFilter僅列出目錄
java version "1.8.0_144"
Java(TM) SE Runtime Environment (build 1.8.0_144-b01)
Java HotSpot(TM) 64-Bit Server VM (build 25.144-b01, mixed mode)
的FileFilter:
private static File maps_dir_src = new File("./maps/");
private static File[] maps_arr_src = maps_dir_src.listFiles(new FileFilter() {
@Override
public boolean accept(File file) {
return file.isDirectory() && !file.getName().toLowerCase().equals("lobby");
}
});
的FilenameFilter:
private static File maps_dir_src = new File("./maps/");
private static File[] maps_arr_src = maps_dir_src.listFiles(new FilenameFilter() {
@Override
public boolean accept(File file, String name) {
return file.isDirectory() && !name.toLowerCase().equals("lobby");
}
});
任何提示嗎?
您可以發佈[ MCVE] – 2017-09-04 18:06:01