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

4

1 回答 1

2

可能问题是您正在尝试“播放”目录(它们也被列出)。检查FileNameFilter

至于一般问题,请创建一个列出目录中所有文件的递归方法,如果找到目录,则再次调用该方法并传递新目录。

于 2013-06-11T21:10:33.947 回答