2

I have this file structure in my android project:

enter image description here

I want to read all the folder names and their file names contained in assets folder. I have tried so many things but I am not able to achieve my goal. Can somebody guide me to correct direction?

Thanks in advance.

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115

3 Answers3

1

You can read the filenames of a particular folder from assets as follows :

private List<String> getFileNames(Context context, String folderName) throws IOException {
        AssetManager assetManager = context.getAssets();
        String[] files = assetManager.list(folderName);
        return Arrays.asList(files);
    }
Suraj Makhija
  • 1,376
  • 8
  • 16
0

Simple read all the assets using the below function

public myClass(Context myContext) {
    AssetManager mngr = myContext.getAssets();
    InputStream is = mngr.open("assests.txt");
}
Harsha W
  • 3,162
  • 5
  • 43
  • 77
0

A simple getAssets().list("") will list all folders.

And files if there are. But you havenot.

greenapps
  • 11,154
  • 2
  • 16
  • 19