1

I have copied some folders to the assets folder. I have many folders inside the assets folder. I want to read all the folders name.

What I am doing is

tx.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { String path = "file:///android_asset/"; Log.d("Files", "Path: " + path); File directory = new File(path); File[] files = directory.listFiles(); Log.d("Files", "Size: "+ files.length); for (int i = 0; i < files.length; i++) { Log.d("Files", "FileName:" + files[i].getName()); } } }); 

But the error it is showing is

java.lang.NullPointerException: Attempt to get length of null array at com.example.ashura.browsetest.MainActivity$1.onClick(MainActivity.java:29) at android.view.View.performClick(View.java:5246) 
1
  • That code will not do. You cannot use the File class as they are no files in assets. Google for assets manager. Commented Mar 5, 2017 at 13:15

1 Answer 1

1

I want to read all the folders name.

Call getAssets() on a Context to get an AssetManager. Call list() on it to retrieve the contents of your assets.

What I am doing is

file:///android_asset/ works for WebView and little else. It does not work with File.

Sign up to request clarification or add additional context in comments.

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.