how to randomly select an image from an arraylist using scanner in java
<p>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!</p>

<pre><code>private ImageIcon iconex; 

        File f = new File("FemaleFaces");
        Scan = new Scanner(f);
        ArrayList&lt;ImageIcon&gt; files = new ArrayList&lt;ImageIcon&gt;();
        while(Scan.hasNext())
        {
            files.add(new ImageIcon(Scan.next()));
        }
        Scan.close();

        int Ffindex = new Random().nextInt(files.size());
        iconex = files.get(Ffindex);
</code></pre>

<p>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)</p>
