I'm trying to scan a folder of images and add them to an arraylist. I want to combine a scanner and random variable to randomly select one of the images from the array list and attach it to to a private ImageIcon icon. "FemaleFaces" is the directory with the images. So far, here is my code and thanks for any help!
private ImageIcon iconex;
File f = new File("FemaleFaces");
Scan = new Scanner(f);
ArrayList<ImageIcon> files = new ArrayList<ImageIcon>();
while(Scan.hasNext())
{
files.add(new ImageIcon(Scan.next()));
}
Scan.close();
int Ffindex = new Random().nextInt(files.size());
iconex = files.get(Ffindex);
Exception in thread "main" java.io.FileNotFoundException: FemaleFaces (Access is denied) at java.io.FileInputStream.open(Native Method) at java.io.FileInputStream.(Unknown Source) at java.util.Scanner.(Unknown Source) at Human.(Human.java:66) at testerobjects.main(testerobjects.java:19)