Android - 按类型筛选 assetManager.list 文件

4

我想要从我的资产目录中获取html文件列表。

以下是代码 >>

private List<String> ListDir(String directory) {
    List<String> result = new ArrayList<String>();
    AssetManager am = getActivity().getAssets();
    String[] files=null;
    try {
        files = am.list(directory);
    } catch (IOException e) {
        e.printStackTrace();
    }
    fileList.clear();
    for (String file : files) {
        result.add(file);
    }
    return result;
}

我该如何筛选出只有 .html 文件呢?
1个回答

4
只需使用endsWith(".xml")
for (String file : files) {
    if(file.toLowerCase().endsWith(".xml")){
        result.add(file);
     }

}

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接