-1

In my application,I want to read the all images from specific folder in File explorer and iterate in for loop. How can i do this?

Phantômaxx
  • 36,442
  • 21
  • 78
  • 108
Bhanuprasad
  • 189
  • 7
  • 19

2 Answers2

3

You can use below code to get all images from specific folder.

1) First you need to define File object to get the storage and appened the name of the folder you want to read.

File folder = new File(Environment.getExternalStorageDirectory().toString() + "/Folder Name/");

2) And now use folder object to get list of files with defined filter. Hope that helps.

if(folder.exists())
File[] allFiles = folder.listFiles(new FilenameFilter() {
public boolean accept(File dir, String name) {
    return (name.endsWith(".jpg") || name.endsWith(".jpeg") || name.endsWith(".png"));
}
});
Abdul Waheed
  • 3,994
  • 4
  • 30
  • 49
2

use this one

    private void showImageList() {
    File file = new 
    File(android.os.Environment.getExternalStorageDirectory() + "/SpyCam/");
    if (file.exists()) {
        String[] fileListVideo = file.list();
        Collections.addAll(arrayList, fileListVideo);

    }
mehul chauhan
  • 1,661
  • 9
  • 19