2
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()
) returns me the following error:
W/System.err: java.lang.Nullpointerexception: Attempt to get length of null array
I already added the permissions!
How do I list files from a folder?
Granted permission ~Runtime read or only in Manifest??
– viana
What value is in your PATH variable?
– viana
I added the PATH there!
– Thiago Luiz Domacoski