Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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.

I have code like this:


AssetManager assetMgr = getAssets();

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

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

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

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
226 views
Welcome To Ask or Share your Answers For Others

1 Answer

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("");

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...