使用AssetManager.list子目录列表资产 [英] List assets in a subdirectory using AssetManager.list

查看:712
本文介绍了使用AssetManager.list子目录列表资产的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序中,我已经倾倒了一堆文本文件,我需要在运行时加载的资产目录。

My application has an assets directory in which I've dumped a bunch of text files I need to load at runtime.

我有一个完整的特定类型的资产(即资产/子目录),我想在一次加载的所有文件在此目录中,之一。

I have a directory full of assets of a particular type (i.e., "assets/subdir") and I want to load all of the files in this directory, one at a time.

我有code是这样的:

I have code like this:


AssetManager assetMgr = getAssets();

String[] assetsIWant = assetMgr.list("subdir");

for(String asset: assetsIWant) {
  doAssetyThing(asset);
}

我已经尝试了无数不同版本的参数对assetMgr.list()和我没有得到任何地方。

I've tried a zillion different versions of the parameter to assetMgr.list() and am not getting anywhere.

如果我用/,我回去包含资产目录列表,以及一些随机其他项目(META_INF,例如)。如果我通过任何其他字符串(如资产或资产/或/资产或/资源/或mysubdir或/ mysubdir或财产/ mysubdir或...)然后我得到返回一个空数组。

If I use "/", I get back a list containing the "assets" directory, and a few random other items (META_INF, for example). If I pass any other string (like "assets" or "assets/" or "/assets" or "/assets/" or "mysubdir" or "/mysubdir" or "assets/mysubdir" or ...) then I get back an empty array.

该文档是相当不幸语无伦次。

The documentation is unfortunately fairly incoherent.

有谁知道正确的公式,该列表()的参数是什么?

Does anybody know what the correct formula for that list() parameter is?

推荐答案

传递一个空字符串,似乎为我工作。我在我的资产目录中的文件列表,当我做了以下内容:

Passing an empty string seems to work for me. I get a list of the files in my assets directory when I do the following:

AssetManager aMan = appContext.getAssets();
String[] filelist = aMan.list("");

这篇关于使用AssetManager.list子目录列表资产的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆