I have the following code:
public static final String PATH ="/Conceitos";
public static List<String> loadFilesName() throws IOException{
List<String> strings = new ArrayList<>(0);
File root = android.os.Environment.getExternalStorageDirectory();
File dir = new File(root.getAbsolutePath()+PATH);
if(!dir.exists()){
dir.mkdirs();
return strings;
}
if(dir.isDirectory()){
for(final File f : dir.listFiles()){
strings.add(f.getName());
}
}
return strings;
}
The folder is already created, and has a file, but when I try to access the list ( dir.listFiles()
) I get the following error:
W / System.err: java.lang.NullPointerException: Attempt to get length of null array
I've already added the permissions!
How do I list the files in a folder?