Android:获取指定文件夹内的所有图片

 1 public static List<String> getFilesAllName(String path){
 2     //传入指定文件夹的路径
    File file = new File(path); 3 File[] files = file.listFiles(); 4 List<String> imagePaths = new ArrayList<>(); 5 for(int i = 0; i < files.length; i++){ 6 if(checkIsImageFile(files[i].getPath())){ 7 imagePaths.add(files[i].getPath()); 8 } 9 10 } 11 return imagePaths; 12 } 13 14 /** 15 * 判断是否是照片 16 */ 17 public static boolean checkIsImageFile(String fName){ 18 boolean isImageFile = false; 19 //获取拓展名 20 String fileEnd = fName.substring(fName.lastIndexOf(".") + 1, 21 fName.length()).toLowerCase(); 22 if(fileEnd.equals("jpg") || fileEnd.equals("png") || fileEnd.equals("gif") 23 || fileEnd.equals("jpeg")|| fileEnd.equals("bmp")){ 24 isImageFile = true; 25 }else{ 26 isImageFile = false; 27 } 28 return isImageFile; 29 }
原文地址:https://www.cnblogs.com/Rainm/p/10547550.html