-1

Basically traversing the entire folder structure. for example, I have a music folder with albums as folders. I also have other miscellaneous songs in the music folder as well.

I have this but it only picks up the other music files and gives me a FileNotFoundException, with the reason being that access is denied to other album folders

    File[] files = new File("C:/Users/Mayank/Desktop/Music/").listFiles();
    private class ButtonListener implements ActionListener {
    public void actionPerformed(ActionEvent arg0) {
        int check = (int) (Math.random()* files.length);
        isPlaying = false;
        mp3.close();
        mp3 = new MP3(files[check].getPath());
        mp3.play();
        isPlaying = true;
    }

EDIT: I see its a duplicate. thanks brain!

Farshid Shekari
  • 2,391
  • 4
  • 27
  • 47

1 Answers1

2

Probably the issue is that you are trying to "play" directories (they are listed as well). Check FileNameFilter.

As for the generic issue, make a recursive method that lists all files in a directory, if it finds a directory call the method again passing the new directory.

SJuan76
  • 24,532
  • 6
  • 47
  • 87