Hello I'm using JFileChooser to get files on the system.
But now I need to use JFileChooser to select folders and add all of their content to the program. I used DIRECTORIES_ONLY
and it worked. Now I want to add all the files (using a filename of file (mp3)) in an arrayList and show to the user. However, I've been around a lot of the internet, and the codes I'm using do not work. Could someone help me?
I need to use JFileChooser, not .walk
Currently, I'm trying to do it like this:
adicionarPasta.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
final JFileChooser chooser = new JFileChooser();
chooser.showOpenDialog(parent);
chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
String diretorio = chooser.getAbsolutePath();//essa linha está com erro
// TODO Auto-generated method stub
File file = new File(diretorio);
File afile[] = file.listFiles();
int i = 0;
for (int j = afile.length; i < j; i++) {
File arquivos = afile[i];
System.out.println(arquivos.getName());
}
}
});