ARTICLE AD BOX
I cannot get a list of files ending with .pdf, I have tried everything, it lists everything else in the folder, except for the pdf's, what is wrong with this. The program then displays the list in a
The folder contains 29 pdf files, and 5 image files(jpg). Please don't suggest using File[] fileList = directory.listFiles();, been there done that, nothing works.
All permissions are set, otherwise I wouldn't get the 5 image filenames
private void getFileList() { fileList = new ArrayList<>(); File directory = getPDFDirectory(); try( DirectoryStream<Path> stream = Files.newDirectoryStream( directory.toPath(), "*.*" )) { stream.forEach( path -> { fileList.add( path.getFileName().toString() ); }); Collections.sort( fileList ); } catch( IOException e ) { Toast.makeText( this, "Cannot read folder", Toast.LENGTH_SHORT ); } }And for those who are curious, here is the getPDFDirectory() code
/** * * @return PDF Folder as a file */ @NonNull private File getPDFDirectory() { return new File( Environment .getExternalStorageDirectory() .getPath() + File.separatorChar + "Documents" + File.separatorChar + "My App" + File.separatorChar + "Files" ); }