List assets in a subdirectory using AssetManager.list

后端 未结 9 596
梦谈多话
梦谈多话 2020-12-04 23:37

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

相关标签:
9条回答
  • 2020-12-05 00:30

    Let's say you have this folder set up: Assets->SubDir1. You have things in Subdir1 like A.txt, B.txt, C.txt. So from the Project's directory, it would be Assets/SubDir1/A.txt.

    Taking that into account, the way to access that file is similar to what you're doing, adding one thing. That one thing is in your doAssetyThing function. You have to put the SubDir1 directory in front of it, even if you did a filter of "SubDir1" in the .list("");

    Example:

        AssetManager am = getResources().getAssets();
        String [] list = am.list("SubDir1");
        for (String s:list) {
            doAssetyThing("SubDir1/" + s);
    
            //I use this next line as the start of copying a pdf from one location
            //to another. I wanted to give you a real function in use.
    
            InputStream inStream = am.open("SubDir1/" + s);
    
            //more code
        }
    

    I hope this is clear and helps you out!

    0 讨论(0)
  • 2020-12-05 00:31

    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("");
    
    0 讨论(0)
  • 2020-12-05 00:32

    For some reason, empty directories are not listed.

    At least, in my experience, they are not listed.

    That is, if you have some-dir/d1/f1 and some-dir/d2 in the assets area, and you list("some-dir"), d2 is not listed.

    0 讨论(0)
提交回复
热议问题