android list files contained in assets subfolder

后端 未结 2 1063
长发绾君心
长发绾君心 2020-12-15 23:44

I create some folders into assets. Each folder contains files that I would like to list. I am using following code but I always get a null value for fileList. Thank you.

相关标签:
2条回答
  • 2020-12-16 00:14

    Simplest would surely be this:

    String[] fileList = getAssets().list("images");
    
    0 讨论(0)
  • 2020-12-16 00:19

    You'll probably want to do this:

    private void listFiles(String dirFrom) {
            Resources res = getResources(); //if you are in an activity
            AssetManager am = res.getAssets();
            String fileList[] = am.list(dirFrom);
    
                if (fileList != null)
                {   
                    for ( int i = 0;i<fileList.length;i++)
                    {
                        Log.d("",fileList[i]); 
                    }
                }
        }
    

    Also your function call should be: listFiles("images"); if you want to list images.

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