-2
Hello I am using Jfilechooser to pick up files on the system.
Only now I need to use Jfilechooser to select folders and add all their contents in the program. I used DIRECTORIES_ONLY
and it worked. Now I want to add all the files (through a file type filto (mp3)) in an arrayList and show to the user. But I’ve already searched a lot of the internet and the codes I find as a base do not serve/do not work. Could someone help me?
I need to use Jfilechooser, not . walk
Currently, I’m trying to do it this way:
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());
}
}
});
Possible duplicate of Read all txt files in a folder
– user28595