I want to process Android files alphabetically. I have tested that in Java on a PC, it sorted the files alphabetically. However, when I tested it in Android, I discovered that Android reads files by size.
Could you help me find a way using which I can read Android files alphabetically?
Android code:
String path = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM) + File.separator + "testface" + File.separator;
Log.d("MyTag", path);
File folder = new File(path);
File[] listOfFiles = folder.listFiles();
Arrays.sort(listOfFiles);
Log.d("MyTag", "no.of files: " + listOfFiles.length);
long startTime2 = System.nanoTime();
for (int i = 0; i < listOfFiles.length; i++) {
if (listOfFiles[i].isFile()) {
String filepath = path + listOfFiles[i].getName();
Log.d("MyTag", "appface_image_filepath: " + filepath);
}
}
Debugging log:
01-01 22:09:11.042 8484-8484/com.example.nasif.facedetectionloop D/MyTag: /storage/emulated/0/DCIM/testface/
01-01 22:09:11.043 8484-8484/com.example.nasif.facedetectionloop D/MyTag: no.of files: 10
01-01 22:09:11.044 8484-8484/com.example.nasif.facedetectionloop D/MyTag: appface_image_filepath: /storage/emulated/0/DCIM/testface/11.jpg
01-01 22:09:11.044 8484-8484/com.example.nasif.facedetectionloop D/MyTag: appface_image_filepath: /storage/emulated/0/DCIM/testface/12.jpg
01-01 22:09:11.044 8484-8484/com.example.nasif.facedetectionloop D/MyTag: appface_image_filepath: /storage/emulated/0/DCIM/testface/17.jpg
01-01 22:09:11.044 8484-8484/com.example.nasif.facedetectionloop D/MyTag: appface_image_filepath: /storage/emulated/0/DCIM/testface/18.jpg
01-01 22:09:11.044 8484-8484/com.example.nasif.facedetectionloop D/MyTag: appface_image_filepath: /storage/emulated/0/DCIM/testface/19.jpg
01-01 22:09:11.045 8484-8484/com.example.nasif.facedetectionloop D/MyTag: appface_image_filepath: /storage/emulated/0/DCIM/testface/20.jpg
01-01 22:09:11.045 8484-8484/com.example.nasif.facedetectionloop D/MyTag: appface_image_filepath: /storage/emulated/0/DCIM/testface/27.jpg
01-01 22:09:11.045 8484-8484/com.example.nasif.facedetectionloop D/MyTag: appface_image_filepath: /storage/emulated/0/DCIM/testface/28.jpg
01-01 22:09:11.046 8484-8484/com.example.nasif.facedetectionloop D/MyTag: appface_image_filepath: /storage/emulated/0/DCIM/testface/3.jpg
01-01 22:09:11.046 8484-8484/com.example.nasif.facedetectionloop D/MyTag: appface_image_filepath: /storage/emulated/0/DCIM/testface/4.jpg