Gregg Bolinger wrote:If you look at the java.io.File API you'll notice that if the File is a directory then you can get a File[] array back of all the files in that directory. Take the size of the array and generate a random number from 0 to files.length. Then use that random number to grab that array index, files[randomNumber].
@OP:
Note that although listFiles() returns an array of File's, this array also contains directories (if present). To get an array of the real files in that directory, you will need to provide a FileFilter and define you only want to get the File instances which return true for File.isFile().