I'm trying to list all the files in a directory. Here is my code:
public List<String> MyFiles = new ArrayList<>();
dir = "/storage/sdcard0";
File f = new File(dir);
File[] files = f.listFiles();
for(File name: files) {
MyFiles.add(name.getName());
}
Collections.sort(MyFiles);
The problem is that nearly all the files is repeated. For Instance I find .nomedia twice and sometimes thrice even thought there is only one file.
Edit:
I changed the code to sort the files correctly thanks to Vishwesh Jainkuniya, but still the same problem the files are repeated.