我想检查/assets/文件夹中是否存在文件。 我该怎么做?请帮忙。
最佳答案
我在我的一个应用程序类中添加了一个辅助方法。我假设是这样;
- Assets 列表在应用运行时不会改变。
List<String>
不是内存占用大户(我的应用程序中只有 78 个 Assets )。- 检查 List 上的 exists() 比尝试打开文件并处理异常要快(我还没有实际分析过这个)。
AssetManager am; List<String> mapList; /** * Checks if an asset exists. * * @param assetName * @return boolean - true if there is an asset with that name. */ public boolean checkIfInAssets(String assetName) { if (mapList == null) { am = getAssets(); try { mapList = Arrays.asList(am.list("")); } catch (IOException e) { } } return mapList.contains(assetName); }
关于android - 如何查看Android Asset资源?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4153246/