I'm writing a slideshow which allows the pictures it shows to be deleted, edited or ignored as they are displayed. It's working fine except for when the directory it's been pointed to contains subfolders. In this case I would like the code to search through the subfolders and also display the images within them. At the moment subfolders are ignored and a null pointer exception is thrown, though images in the main directory are read and displayed. This is the relevant section of the code:
String files;
File folder = new File(path); //Loads folder
File[] listOfFiles = folder.listFiles(); //assigns filenames to array
for (int i = 0; i < listOfFiles.length; i++) {
//Some code here deals with graphics
Random randomGenerator = new Random(); //Initiates random generator
int randomInt = randomGenerator.nextInt(listOfFiles.length); //Limits max random to lenth of folder array
files = listOfFiles[randomInt].getName(); //Chooses a filename based on random number
final String fileID = "file:///" + path + "\\" + files; //creates path to display
currentFile = path + "\\" + files; //Assigns filename to variable ready for deletion later
}
I need to treat these more as discrete images rather than just printing out a list of them. I've excluded from the code here the snippet which deals with painting to the screen (g.drawImage).
If anybody suggests Apache Commons IO FileUtils, would you be kind enough to explain how I go about downloading, installing and then importing the correct libraries, as I've been having trouble achieving this (if it even works). I would prefer a solution which doesn't require non-standard libraries. I have read that it is do-able in Java 8 (which I'm using) but I've not been able to find any relevant examples.
I apologise if this turns out to be a duplicate question, but I've been unable to find a similar example that quite matches these requirements. Most other examples seem content simply to list the files, rather than perform an action with them.
Many thanks in advance.