I have a folder in root with some files I want to list but the array returns null:
String path = getenv("EXTERNAL_STORAGE") + "/Files";
File directory = new File(path);
File[] files = directory.listFiles();
Permissions are granted
I have a folder in root with some files I want to list but the array returns null:
String path = getenv("EXTERNAL_STORAGE") + "/Files";
File directory = new File(path);
File[] files = directory.listFiles();
Permissions are granted
First off, you need to use Environment.getExternalStorageDirectory()
instead of getenv()
:
String path = Environment.getExternalStorageDirectory().toString() + "/Files";
File directory = new File(path);
File[] files = directory.listFiles();
for (int i = 0; i < files.length; i++)
Log.d("Files", "FileName:" + files[i].getName());
But a very important note is the /storage/emulated/0
folder does not really exist. It's what might be called a "symbolic link", or, in simpler terms, a reference to where the real data is stored. That's why your array returns null. You'll need to find the actual physical location on your device where it is stored.