Question

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?

Was it helpful?

Solution

Just use endsWith(".xml").

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

}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top