android - 按类型过滤 assetManager.list 文件 [英] android - filter assetManager.list files by type
本文介绍了android - 按类型过滤 assetManager.list 文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想从我的资产中的特定目录中获取我的 html 文件列表.
I want to get a list of my html files from a specific directory in my assets.
有代码>>
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 文件?
How can I filter my files in just .html ones?
推荐答案
只需使用 endsWith(".xml")
.
for (String file : files) {
if(file.toLowerCase().endsWith(".xml")){
result.add(file);
}
}
这篇关于android - 按类型过滤 assetManager.list 文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文