【问题标题】:android - filter assetManager.list files by typeandroid - 按类型过滤assetManager.list 文件
【发布时间】:2013-09-26 18:28:06
【问题描述】:

我想从我的资产中的特定目录中获取我的 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 文件?

【问题讨论】:

    标签: android android-file android-assets


    【解决方案1】:

    只需使用endsWith(".xml")

    for (String file : files) {
        if(file.toLowerCase().endsWith(".xml")){
            result.add(file);
         }
    
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-02-02
      • 1970-01-01
      • 2015-10-13
      • 2019-06-03
      • 1970-01-01
      • 2012-02-14
      • 2014-06-21
      • 2014-12-01
      相关资源
      最近更新 更多