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.

3
  • you can read assets folder like AssetManager mngr = myContext.getAssets(); InputStream is = mngr.open("filename.extention "); Commented Mar 27, 2017 at 6:17
  • stackoverflow.com/questions/8458433/… Commented Mar 27, 2017 at 6:18
  • all the folder names and their file names? Folder names ok. But if it is a folder then how could it have a file name? Commented Mar 27, 2017 at 7:05

3 Answers 3

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); } 
Sign up to request clarification or add additional context in comments.

Comments

0

Simple read all the assets using the below function

public myClass(Context myContext) { AssetManager mngr = myContext.getAssets(); InputStream is = mngr.open("assests.txt"); } 

Comments

0

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

And files if there are. But you havenot.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.