android - filter assetManager.list files by type

青春壹個敷衍的年華 提交于 2019-12-01 18:40:40

问题


I want to get a list of my html files from a specific directory in my assets.

There is the code >>

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;
}

How can I filter my files in just .html ones?


回答1:


Just use endsWith(".xml").

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

}


来源:https://stackoverflow.com/questions/18932486/android-filter-assetmanager-list-files-by-type

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!