-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!

1
  • so it wont pick up say a .txt file? Also can you post the actual stack trace? Commented Jun 11, 2013 at 21:09

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.